#help-archived
1 messages ยท Page 81 of 1
you stated
all enums are singletons
#equals cannot return false if reference equality is true
unless equals is overridden
it can't be overridden in enums
how many of you here have studied software engineering at uni here
i am a software engineer of 40 years
wow nice
Not me. I started learning Java last summer, so not even a year.
what languages
Singletons are in classes not in enums, an enum is an constant not a singleton @runic wadi
an enum is a singleton
wtf is a singleton
yeah I assume when you're so shit at java that ur arguing over nothing with more experienced people, and say .equals is a common practice to use on enums
in fact an enum is the best way to enforce a singleton
What I find ironic is the amount of users who claim they have so much experience but don't know these basic terms.
its not @runic wadi
I do not mean offense.
I am studying software engineering atm
No c++ and C
damn
@runic wadi retarded
Java is similar anyways...
This is so incredibly hilarious because I'm the only one who noticed that temedy asserted that the same condition can produce different results.
Yeah but if you learn c++ it is easy peasy to learn java
Same goes for C#
a language easy to learn
c#?
Further, I find it ironic that users who claim so much experience are arguing over Java basics.
is that some windows applications crap
why is he saying enums aren't singletons ๐
For instance, enums are technically not singletons because there are multiple instances of the enum.
Its not the same condition, but no point arguing with someone that has basically no experience and probably coding some shit plugins in spigot and some real shit code, no shit when youve started java in summer and ur tryna act like ur smarter than everyone and arguing with more experienced people @marsh nova
okay that is wrong
There is no multiple instance of an enum, its a static final
an enum is one instance
and singleton is used whenever u wanna get 1 instance of a class instead of creating an new instance
decompiling java programs is ez
temedy, it is so ironic that you think because I have only started Java last summer that you are somehow entitled to a superior position. Nothing could be more wrong.
its basically a static method like getInstance()
well it seems like it, you are really shit at java if you think its common practice to do stuff that isnt common practice
im not arguing with you anymore
basically, theres no point when u cant understand a thing
I think it is good to accept criticism from people who have more experience. (Something I was bad at accepting but it helps me alot )
It isn't a competition
People with more experience generally try to help so you can take it or leave it
up to you
temedy, I also find a few more things odd. First, you would think that one's tendency to use #equals indicates poor programming in that user's entirety. Second, you think that the person you are speaking do "cant understand a thing" merely because you realise you've said something wrong.
I havent said nothing wrong?
Guys relax
@runic wadi you should stfu because you dont even know what a fucking singleton is
So, temedy, in fact, it would rather appear that your great years of experience have failed you.
you're wrong
what is it that ur arguing about anyway
well I was right in everything, u guys just have none java experience so u cant understand at all
Can we stop calling people out and just say what is right or wrong?
...
There doesnt need to be arguments here
i'm actually implementing a singleton pattern right now using enums
I think neither of you know what a singleton is, at least according to the common definition of the term. A singleton is a design pattern where there is only 1 instance of the class. There are multiple instances of an enum class, one instance for each constant.
and singleton is used whenever u wanna get 1 instance of a class instead of creating an new instance
"neither of you know what a singleton is"
w/e
im not very familier with enums i have never used them in practice yet
unless i have and i did not know i had
That is completely fine.
@brisk mango https://lmgtfy.com/?q=java+enum+singleton+pattern you can begin your education here
it's good to get started at a young age
enums are great with switch statements.
lol
i think you should learn the difference between singletons and constants
click it, it can help you correct your knowledge
noobie plugin dev is telling me to start my education while he doesnt know himself what a singleton/constant is
An enum can be used to implement a singleton but enums are not necessarily singletons. Consider the following enum:
public enum SomeEnum {
VALUE1,
VALUE2,
VALUE3
}
that is not a singleton
there are 3 instances of SomeEnum
The enum itself is therefore not a singleton.
enums are one instance, optionally with instance fields and created using a constructor
but you cannot instantiate them yourself
because there is one inherent instance
and that is a singleton
There is one instance of each constant in the enum, but there are multiple instances of the enum.
Thus, strictly speaking, the enum itself is not a singleton.
Yes, I know what you mean.
I guess I learned something today
public enum SingletonEnum {
INSTANCE;
int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
Never really looked at enums this specifically
That SingletonEnum is a singleton but not only because it is an enum, but because it is an enum and there is only 1 constant in the enum.
if there are 3 enums instead of 1, each one is a singleton and they are always equal to themselves but not one another
I know that an instance is thread-safe but you just have to make sure that methods and data that the instance carries is also thread-safe
In the context of Java, a singleton usually refers to a type, such that there may only be 1 instance of a certain class, but I guess you could say, in a sense, that each enum constant is its own singleton.
Is there method to set/modify the name displayed above player's heads within Spigot/Bukkit?
Instances themselves are always thread safe โ assignation is thread safe, reference equality is thread safe. Just ensure that concurrent reads happen to volatile fields where applicable.
There is no simple method zen.
As far as I know.
Is there any complicated methods (if not simple lol) then?
Not off the top of my head
@gusty comet im pretty u have to use a plugin for that
But there are plugins which do that
I'm trying to make a plugin to do that lol
im making a simple rank and nick system for my personal use
You can do it with scoreboard teams if you want to avoid nms
im pretty sure the spigot api does not have a direct method to do it
NMS stands for 'net.minecraft.server'
i think the scoreboardt teams only adds text to the player's name below
meaning accessing implementation details directly
but it has to be done with reflection if you wanna do that
not necessarily
if your project is only for 1 version, you can simply use nms directly
if you need compatibility with multiple versions, you can use a multi-module setup and abstraction
That is true but I recommend to have to compatibility for multiple versions.
So it is future proof.
then again... code changes sometimes anyways
I prefer abstraction over reflection, because it is easier to manage differences in NMS details.
but does scoreboard teams change the actual name above the players head
or does it just add a new line of text
With reflection your code silently breaks unless you test it. It defeats the purpose of static typing.
Yeah that is true.
I saw a thread on stackoverflow comparing reflection versus abstraction
and it seems the abstraction is faster too
pretty sure people use reflection in order to avoid importing version-specific classes
@frigid ember scoreboards only add new text. To change the playername you will need to edit the gameprofile or PlayerInfoData packets
protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER) {
return;
}
PlayerInfoData pid = event.getPacket().getPlayerInfoDataLists().read(0).get(0); //get the original packet to set the skin later
PlayerInfoData newPid = new PlayerInfoData(pid.getProfile().withName(finalName), pid.getLatency(),
pid.getGameMode(), WrappedChatComponent.fromText(name));
newPid.getProfile().getProperties().putAll(pid.getProfile().getProperties()); //Set the skin of the new PlayerInfoData to the original skin from the original PlayerInfoData
event.getPacket().getPlayerInfoDataLists().write(0, Collections.singletonList(newPid)); //Overwrite the packet
String finalName //Name to change player's name to
example using protocollib to not change the name in chat, but only above player head
just make lambda metafactories for every nms method you need
yeah thats what i thought
inline fun <reified F> metafactory(
process: MethodType.() -> MethodType,
methodhandlefunc: (MethodHandles.Lookup) -> MethodHandle
): F {
val lookup = MethodHandles.lookup()
val methodhandle = methodhandlefunc(lookup)
val func = methodhandle.type()
val invoked = MethodType.methodType(F::class.java)
val callsite = LambdaMetafactory.metafactory(
lookup, "invoke", invoked,
func.process(), methodhandle, func
)
val factory = callsite.target
return factory.invoke() as F
}
```metafactory maker ๐ค
makes the factories that make lambdas
faster than reflection
basically produces a functional interface for every method
Have you tested it?
yes of course
What were the results
it's like using nms directly
do not recommend using in java though; kotlin extension methods help a lot
Yeah I haven't had the need to switch over to kotlin so I am on java atm
Could you show me an implementation of the metafactory?
val isTileEntity: Any.() -> Boolean = metafactory(MethodType::generic) { l -> l.findVirtual(blockClass, "isTileEntity", MethodType.methodType(Boolean::class.java)) }
there now you have a lambda for isTileEntity
obviously you need to invoke this on a block
Oh yeah I see
there is no type safety with Any, but we're not looking for safety if we're doing this shit
I know this is probably freaking stupid but How do I purchase plugins? I click buy plugin and it just brings me up say your are purchasing *plugin name and doesnt have a purchase or buy button?
If there is no paypal set, I don't believe it actually gives you the option to buy it. Otherwise, it should let you click on a button that re-directs you to the paypal payment site.
And... he left. lol
Been a few years since I ran a self-hosted bukkit minecraft server and am running into some problems. It is my understanding that I want to run craftbukkit.jar on my server but am having some issues:
- I got the latest craftbukkit jar from <website link removed upon request> - 1.15.2
- When run it throws an error claiming it's outdated:
*** Error, this build is outdated ***
*** Please download a new build as per instructions from https://www.spigotmc.org/go/outdated-spigot ***
*** Server will start in 20 seconds ***
- This seems odd since no newer version was listed was the latest and matches the current Minecraft server version number, but I'll bite.
- I follow the link which redirects to https://www.spigotmc.org/wiki/buildtools/ and unlike the error message only has instructions to build spigot/craftbukkit from source. Sure, let's do that.
- As detailed there, I download the latest BuildTools.jar and run
java -jar BuildTools.jar --rev latest - The instructions claim "You can find CraftBukkit and Spigot in the same directory you ran the the BuildTools.jar" but no craftbukkit jar file was created, only spigot-1.15.2.jar
So I'm trying to be a good boy and update so I don't have an error thrown in stderr which is messing up my supervisor and don't have to wait 20 seconds, but as far as I know I already had the latest version, and when I follow the instructions to build from source I also don't seem to get the jar I need.
Any tips on where I went wrong?
While it is recommended to use the latest build it isn't really an error. More of a warning
it's output to stderr
nvm I didnt' read the question properly
am I misunderstanding that I need 'craftbukkit.jar'? or is the 'spiggot.jar' file output by buildtools sufficient?
Incidentally, why not just run the spigot jar?
honestly, I wasn't sure what was the API and what was the server to run, heh. if spiggot works then I'll use that
@quartz quiver Would you please remove the first link in your message?
spigot is basically an extension to bukkit, and a drop in replacement
Does anyone know how I can make an inventory that you can input a number into
Legality reasons ๐
understandable
also, was that 'IReallyKnowWhatImDoing' flag that was posted temporarily real? XD
it's real yes
exactly that
@stark salmon what have you tried?
@ECHO OFF
java -Xms1024M -Xmx2048M -DIReallyKnowWhatIAmDoingISwear=true -jar spigot.jar nogui
Yes it is real
it is to remove the warning message
I tried making a normal inventory GUI and using a stack of an item already in it to count with
yep, understandable. I was half expecting one to exist, but hadn't poked at the source yet
weird, where is it documented?
the whole point is that you are meant to look at source code to see it I'm guessing, thereby proving its claim
but it's bad and idk how to detect how many of an item is in a slot
can i make a custom sized inventory gui?
I don't think so. There has to be 9 columns in each row and up to 6 rows to not break things.
oh ok
So it removes the warning about your server jar being out of date?
Yes that is the only functionality for the flag
should have an alias ImTooLazyToRunBuildTools
Although there are times you can be too aggressive, I just happened to get lucky enough to update right when a bug was released, woke up the next day and there were way too many mobs everywhere.
lol
well sorry about the questions but i give up on a GUI how do I get the options passed to the command?
Do you care how many rows are in your inventory?
You just want to be able to figure out the number of items in the stack of a particular slot?
WTF is wrong with Shockbyte
is this a good way to create a gui (I used to implement InventoryHolder but I was told thats bad) https://pastebin.com/25VnZFcp
They're bragging about ancient Xeons and bragging about how they have the best hardware vs their competitors
They literally rent from OVH like everybody else
lol
"We are the biggest provider in Asia Pacific" like i give a fuck on the NA website
idk ovh does make a fortune off of resellers
funny cuz they told me in an older ticket that they own all their 'revolutionary hardware'
Well, by revolutionary, they mean it marches around with pitchforks
revolting abt their sht customer service i bet
lol
yeah im certainly shocked by my experience
are they pricey?
no thyre cheap
oh
lol
Well, there's your answer, you get what you don't pay for.
I self host lol
100% uptime unless theres a power outage
my backup battery only lasts for 1 hour
I switched to Skynode then ovh
Must be nice, having a serviceable connection
VPS?
Have you tried vms from OVH?
skynode vps then ovh dedis
or are you using dedicated?
yeah
$125 rip
for all you know they are just glorified raspberry pies with a price tag
"dedicated"
Hey, that gives me an idea..
I've got two pi's sitting around doing nothing. Time to start a hosting service
public boolean playerFileExists(String UUID) {
File playerFile = new File(pluginPath + File.separator + "Players", UUID + ".json");
return playerFile.exists();
}``` how does this throw NPE?
I dont get it
plugin.getDataFolder()?
I had some weird issues with using File.separator
What's the value of pluginPath?
String path = playerFilePath + File.separator + defaultPlayerFile;
File file = new File(plugin.getDataFolder(), path);
Im changing the definition of that to the constructor
That's an example of how I'm using it in one place
this is an example of what I do uuidFile = new File(getDataFolder(), "uuid.yml"); if (!uuidFile.exists()) { uuidFile.getParentFile().mkdirs(); saveResource("uuid.yml", false); }
idk about the file separator though
never used it
so for example, if your file is in your plugin's data folder: plugins/myplugin/Players/playerUUID.json
// String playersFolderPath = "Players";
// String playerFile = UUID + ".json";
String path = playersFolderPath + File.separator + playerFile;
File file = new File(plugin.getDataFolder(), path);
Im working on it lol
If you're calling this from within your plugin class, then obviously you wouldn't have plugin.getDataFolder(), it would just be getDataFolder()
Oh
its not even related to that
Im stupid
I gave an instance of something that hadnt been instanced yet
lol
Yeah that'll do it
I think that type of thing comes with the territory, overlooking a small typo or detail, and you debug for hours.
It happens
Incidentally, for those of you self hosting or running a dedicated server, what flavor of linux do you use?
I mean I've got 5 years of experience
and I cant believe I didnt see thruogh it
through*
Lol, I've been programming for probably 35+ years, and it still happens every so often, though more likely because of age at this point.
OK so I made a custom command, packaged it and all but the command won't show up
I use arch for my server
nvm it was an error
i found the error
was it one of those user id 10t errors? I make a those every once in a while.
it was something about command description
[00:27:09 ERROR]: Could not load 'plugins/VaultToEmeralds.jar' in folder 'plugins'
org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type
at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:1008) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:246) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:166) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:148) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.loadPlugins(CraftServer.java:359) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:234) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:895) ~[patched_1.15.2.jar:git-Paper-240]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222-ea]
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:990) ~[patched_1.15.2.jar:git-Paper-240]
... 7 more
That seems to indicate that a description is supposed to be a Map, and not a String.
Where's Dora, when you need her, amirite?
It's a data structure
i've used java for years but w h a t
Uses Keys and Values
oh
ok
do you want to see my plugin.yml
main: com.masonmeirs.vaulttoemeralds.VaultToEmeralds
name: VaultToEmeralds
version: 1.0
author: Mason Meirs
description: Converts money to emeralds. 250$ = 1 emerald.
commands:
convertmoney:
description: Converts money to emeralds.
usage: /convertmoney
permission: vaulttoemeralds.convertmoney
permission-message: You don't have the convertmoney command permission.
Can someone help me load the corners of the map
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
// int mY = maxValue(map.getScale());
if (switc) {
map.getRenderers().clear();
map.getRenderers().add(this);
}
worldMap.decorations.clear();
map.setCenterX(player.getLocation().getBlockX());
map.setCenterZ(player.getLocation().getBlockZ());
map.setWorld(player.getWorld());
for (int x = 1; x < 128; ++x) {
for (int y = 1; y < 128; ++y) {
canvas.setPixel(x, y, worldMap.colors[y * 128 + x]);
}
}
}
What's your end goal? to just reveal the whole area?
@stark salmon I would suggest removing the ambiguous symbols
$, =, .
ok
@red zenith I'm trying to load the corners of the map without the player walking there. What my total goal is, is that I'm trying to zoom in and out of maps, but when I zoom out it sets it to a circle
thank you
So instead of having to use multiple copies of a map, one for each scale, you're creating a system that lets you scale in and out the map, using one item?
@frigid ember still same error
main: com.masonmeirs.vaulttoemeralds.VaultToEmeralds
name: VaultToEmeralds
version: 1.0
author: Mason Meirs
description: Converts money to emeralds 250 dollars is 1 emerald
commands:
convertmoney:
description: Converts money to emeralds
usage: /convertmoney
permission: vaulttoemeralds.convertmoney
permission-message: You don't have the convertmoney command permission.
Your spacing is wrong
oh
indent description and everything after
reduce the indent of convertmoney
commands:
convertmoney:
description: Converts money to emeralds
usage: /convertmoney
permission: vaulttoemeralds.convertmoney
permission-message: You don't have the convertmoney command permission.
Yeah, my bad I did the opposite
main: com.masonmeirs.vaulttoemeralds.VaultToEmeralds
name: VaultToEmeralds
version: 1.0
author: Mason Meirs
description: Converts money to emeralds 250 dollars is 1 emerald
commands:
convertmoney:
description: Converts money to emeralds
usage: /convertmoney
permission: vaulttoemeralds.convertmoney
permission-message: You don't have the convertmoney command permission.
wait 2 or 4 spaces
Oh it worked
but not both
thank you
๐
first plugin lol
gl lol
the code is... mess
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack emeralds = new ItemStack(Material.EMERALD);
try {
emeralds.setAmount((int) clamp(Integer.parseInt(args[0]),0,255));
}
catch(Exception e) {
sender.sendMessage(e.toString());
sender.sendMessage("You probably put a negative number or put a very high number. Don't do that.");
}
int moneyNeeded = (int) (clamp(Integer.parseInt(args[0]),0,255) * 250);
if(economy.has(((Player) sender).getPlayer(), "world", (double)moneyNeeded)) {
economy.withdrawPlayer(((Player) sender).getPlayer(), moneyNeeded);
player.getInventory().addItem(emeralds);
} else {
sender.sendMessage("Not enough funds! $250 = 1 emerald.");
}
}
return true;
}
just an example
of mess
oh for the parseint
when the parseint throws an exception
like if you put a letter instead of a number or something
you should use NumberUtils.isInt
Yeah NumberUtils is a good replacement
immediately i get an internal error occured while running this command :/
nice, what's the error?
NullPointerException
The command is registered?
What's the full error
it's probably args[0]
you aren't checking if the length of args > 0
so trying to get args[0] is null
Where do you set the economy variable
yeah you probably aren't setting it anywhere
package com.masonmeirs.vaulttoemeralds;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.milkbowl.vault.economy.Economy;
public class CommandEmeralds implements CommandExecutor {
public static Economy economy = null;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack emeralds = new ItemStack(Material.EMERALD);
try {
emeralds.setAmount((int) clamp(Integer.parseInt(args[0]),0,255));
}
catch(Exception e) {
sender.sendMessage(e.toString());
sender.sendMessage("You probably put a negative number or put a very high number. Don't do that.");
}
int moneyNeeded = (int) (clamp(Integer.parseInt(args[0]),0,255) * 250);
if(economy.has(((Player) sender).getPlayer(), "world", (double)moneyNeeded)) {
economy.withdrawPlayer(((Player) sender).getPlayer(), moneyNeeded);
player.getInventory().addItem(emeralds);
} else {
sender.sendMessage("Not enough funds! $250 = 1 emerald.");
}
}
return true;
}
public static float clamp(float val, float min, float max) {
return Math.max(min, Math.min(max, val));
}
}
theres the entire class
public static Economy economy = null;
public static Economy economy = null; well thats why
from vault
you're setting it to null
it probably shouldn't be static either
for now you can keep it
you're learning basics
just keep that in mind once you figure this out
ok
idk what to do tho because if i dont do that i cant reference it because its not static
also, you could probably make a helper utility class and put your clamp method in that
oh
@stark salmon Dependency Injection
In case you end up wanting to use it later
what's that
basically setup the economy variable in the main class and then have a public Economy getEconomy()
ok
then when you create the new CommandClass() you pass your main class as an argument
can someone helpme? I posted my password on github (private repo) what can I do to remove it?
In very simple terms it means passing a dependency, vault economy in this case, as a parameter to your Commands constructor
how do i do that tho, im a little dense
ty
Well, in your onEnable method you have to construct and register your command class
cark you can define the command constructor to require the main class argument with
private Main main;
public CommandEmeralds(Main main) {
this.main = main;
}
So you would add a constructor to your CommandEmeralds class.
Like that
so main which is in your CommandEmeralds class is set to the instance of your main class if that makes sense
ok
What's the name of your plugin class?
the name is VaultToEmeralds
The method a(ItemStack, ItemStack) in the type Item is not applicable for the arguments (ItemStack, World)
Why is this not working?
what line @frigid ember
alright so then
private VaultToEmeralds plugin;
public CommandEmeralds(VaultToEmeralds plugin) {
this.plugin = plugin;
}
put that in my CommandEmeralds()?
yes
ok
@torn robin
WorldMap worldMap = ItemWorldMap.a(player.getItemInHand(), player.getWorld());
You have to get the economy instance though
for some reason .a is looking for an additional ItemStack instead of the world
ok
do you have the source code for a?
@frigid ember is that code itself not working? Have you written any code yourself trying to implement ItemWorldMap? What are you trying to do?
So you have something like the setupEconomy method in your VaultToEmeralds class?
im making it rn
That checks to make sure that vault is loaded, and then uses a service provider to get an instance of the economy class from vault.
im trying to figure out how to get the world's economy
because there isnt a method to get the current economy
If you notice in that code example, cark, there's also a static method
public static Economy getEconomy() {
return econ;
}
If you add that then you don't need a constructor in your CommandEmeralds class.
You should be able to just call Economy econ = VaultToEmeralds.getEconomy(); in your onCommand method, inside your first if statement.
Then you can remove public static Economy economy = null; from your CommandEmeralds class
oh
So you would need to add that in your plugin's class
do I put the snippet in CommandEmeralds or VaultToEmeralds
the one you posted here
I've posted several.
The first thing you need to do is make sure your VaultToEmeralds class that extends JavaPlugin
has the methods required to connect to the VaultAPI
plus private static Economy econ = null; at the top
setupEconomy is what's supposed to assign an instance to that variable
do I call setupEconomy from onEnable?
Do you see the onEnable code in that link?
oh yeah
If you're not going to use the permissions or chat api from vault then you can just leave out the code for that
that's what the logger does
oh
public static Economy economy = VaultToEmeralds.getEconomy();```
Bukkit.getConsoleSender().sendMessage("hello"); another alternative
does that make sense at the top of my commandEmeralds
getLogger().severe("Danger Will Robinson!")
By using getLogger() it appends the name of your plugin in front of the console message
ok
System.out.println(ChatColor.RED+"Danger Will Robinson!");
I don't think System.out.println does that
public static Economy economy = VaultToEmeralds.getEconomy();
Can I put this on top of CommandEmeralds
or will this cause something bad
don't really need to do that
oh ok
oh
and you don't know when that's going to be called. remember, that Economy instance isn't set until your plugin retrieves it using the API
so do I just call the geteconomy method whenever I need to use it
If you don't want to keep calling it multiple times in the same method, then you can just assign it to a variable in your method
ok
Economy economy = VaultToEmeralds.getEconomy();
package com.masonmeirs.vaulttoemeralds;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.milkbowl.vault.economy.Economy;
public class CommandEmeralds implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Economy economy = VaultToEmeralds.getEconomy();
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack emeralds = new ItemStack(Material.EMERALD);
try {
emeralds.setAmount((int) clamp(Integer.parseInt(args[0]),0,255));
}
catch(Exception e) {
sender.sendMessage(e.toString());
sender.sendMessage("You probably put a negative number or put a very high number. Don't do that.");
}
int moneyNeeded = (int) (clamp(Integer.parseInt(args[0]),0,255) * 250);
if(economy.has(((Player) sender).getPlayer(), "world", (double)moneyNeeded)) {
economy.withdrawPlayer(((Player) sender).getPlayer(), moneyNeeded);
player.getInventory().addItem(emeralds);
} else {
sender.sendMessage("Not enough funds! $250 = 1 emerald.");
}
}
return true;
}
public static float clamp(float val, float min, float max) {
return Math.max(min, Math.min(max, val));
}
}
here's my finished code
the build time skyrockted lol
96 ms -> 306 ms
One other thing I'll mention, you call this code twice.
(int) clamp(Integer.parseInt(args[0]),0,255)
you could just call it once and assign it to a variable:
int numEmeralds = (int) clamp(Integer.parseInt(args[0]),0,255);
int moneyNeeded = numEmeralds * 250;
oh ok
ok i just added that and rebuilt, time to scp it to my server
moment of truth
No errors
time to run it
You registered it in your main class as well?
Another thing, if your clamp method is only going to be used to create an int you can change it to:
public static int clamp(float val, float min, float max) {
return (int)Math.max(min, Math.min(max, val));
}
that way you don't have to cast the result
org.bukkit.command.CommandException: Unhandled exception executing command 'convertmoney' in plugin VaultToEmeralds v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.15.2.jar:git-Paper-240]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:760) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1854) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1662) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[patched_1.15.2.jar:git-Paper-240]
at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.15.2.jar:git-Paper-240]
at ...
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222-ea]
Caused by: java.lang.NullPointerException
shit
Are there more lines to the error
yeah but it was over 2000 chars
just copy starting with the Caused by: and the next couple of lines
ok
anything that references your class/package
Caused by: java.lang.NullPointerException
at com.masonmeirs.vaulttoemeralds.CommandEmeralds.onCommand(CommandEmeralds.java:26) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.15.2.jar:git-Paper-240]
... 17 more
so what's line 26 of your CommandEmeralds class?
int moneyNeeded = (int) (clamp(Integer.parseInt(args[0]),0,255) * 250);
wait
i changed it
must be args
oh
Are you only testing this on your remote server?
I mean you're not testing a local server
im not
I set up a local one for development
oh
because I have to restart it frequently
im testing on my server that currently has players..
ive caused so many memory leaks by reloading its unreal
Well, I would normally restart the server entirely
which is why I use a local development copy of my server
oh
The method parseInt(String) in the type Integer is not applicable for the arguments (String[])
uhm
you typed args instead of args[0] or whatever argument
oh
but it was args[0] when i got the error
Can you paste the code
Did you restart your server after you uploaded your plugin?
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Economy economy = VaultToEmeralds.getEconomy();
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack emeralds = new ItemStack(Material.EMERALD);
try {
emeralds.setAmount((int) clamp(Integer.parseInt(args[0]),0,255));
}
catch(Exception e) {
sender.sendMessage(e.toString());
sender.sendMessage("You probably put a negative number or put a very high number. Don't do that.");
}
int moneyNeeded = (int) (clamp(Integer.parseInt(args[0]),0,255) * 250);
if(economy.has(((Player) sender).getPlayer(), "world", (double)moneyNeeded)) {
economy.withdrawPlayer(((Player) sender).getPlayer(), moneyNeeded);
player.getInventory().addItem(emeralds);
} else {
sender.sendMessage("Not enough funds! $250 = 1 emerald.");
}
}
i did
if (args != null && args.length > 0) {
// Do stuff
}
else {
// Send an error message
}
you were providing a value to your command when you used it right?
/convertmoney 5
Nvm I think I was wrong
oh ok
and you're calling your command from in game and not the console, correct?
yeah
Someone is creating fake accounts to give negative reviews to my plugin
Is this a reason of reporting?
YOo I actually have this on my server
thank you a lot :)
no problem ๐
i still get a nullpointerexception at line 26 even though it's a {
what the fuck
god i should not be writing a plugina t 1:40
am
especially my first one
Can someone please help me, for some reason players can drag items out of my gui https://pastebin.com/cdLrQeQK
are you cancelling gui drags
I'm canceling click event
oh
@EventHandler
public void onInventoryClick(final InventoryDragEvent e) {
if (e.getInventory() == inv) {
e.setCancelled(true);
}
}
it worked when I was implementing InventoryHolder (but I was told not to do that)
try that
oh
SlimeLoader loader = SPlugin.getLoader("file");
final Player player = (Player) event.getWhoClicked();
if (event.getInventory() != CreateGUI(player)) return;
event.setCancelled(true);```
idk then, im new to plugins
it's okay
i cant even get my own plugin working
need help?
ok
you're using vault right?
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
int emsreq = (int) clamp(Integer.parseInt(args[0]),0,255);
Economy economy = VaultToEmeralds.getEconomy();
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack emeralds = new ItemStack(Material.EMERALD);
try {
emeralds.setAmount(emsreq);
}
catch(Exception e) {
sender.sendMessage(e.toString());
sender.sendMessage("You probably put a negative number or put a very high number. Don't do that.");
}
int moneyNeeded = emsreq * 250;
if(economy.has(((Player) sender).getPlayer(), "world", (double)moneyNeeded)) {
economy.withdrawPlayer(((Player) sender).getPlayer(), moneyNeeded);
player.getInventory().addItem(emeralds);
} else {
sender.sendMessage("Not enough funds! $250 = 1 emerald.");
}
}
return true;
}
thats my code
Caused by: java.lang.NullPointerException
at com.masonmeirs.vaulttoemeralds.CommandEmeralds.onCommand(CommandEmeralds.java:26) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.15.2.jar:git-Paper-240]
... 17 more
this happens
my plugin uses vault if you want to look at the source code (in the meantime I'll look though that chunk of code) https://repo.voidcitymc.com/ramdon-person/SimplePolice/src/branch/master/SimplePolice/src/com/voidcitymc/plugins/SimplePolice/worker.java
ok
what does this do? ((Player) sender).getPlayer()
why not just cast it?
why add the .getPlayer
that's unnecessary ye
just call that, you don't need to keep casting it
what?
code?
it keeps changing it to the old one
I'm using eclipse
when I do sender.getPlayer() it changes it back to the casted one
and i cant stop it
oh
I see you have Player player = (Player) sender;
no need to keep casting
just use player
ok
well whenever I save eclipse auto-builds
sender.getPlayer is being auto casted because eclipse has to cast it as it's a CommandSender not a Player
just to be safe I would click export then jar file
so you have to use the player variable otherwise it will keep casting it
you can select
right click the project
export everything in the project
ok
thats what I do lol
I'm retarded
such a time waster lol
xd
๐
Is there a way to detect if someone is holding right click on a block for let's say 30 seconds?
IT WORKS
good
yeahhhhhhhh
Is there a way to detect if someone is holding right click on a block for let's say 30 seconds?
@trim fjord maybe add a listener to playerinteractevent on block and just print some debug to the console, im honestly not sure if the event repeats per tick or its just once
you'll have to do some investigative work yourself
I have, this is what I am doing so far
thank you guys
I am currently using a Map storing their UUID and a Long, then later on using that map to check
if (System.currentTimeMillis() - lastClicked.get(p.getUniqueId()) > 30000)
// If the current millis - the lastClicked time is greater than > 30 seconds
Literally in my head simple but not so simple after all.
The fact of the matter is I just want to basically detect if they stop right clicking. If they do, then it doesn't run at all, however, if they continue to hold right click till it's >= 30 seconds it'll do something
I guess you have to write a method for this
Search for things like onkeypress down for jaca
Java*
And cancel ur timer with another method for onkeypressup
Something like a key listener
There is definetly something out there
what, for minecraft server?
For his plugin yes
He wants to know how long right klick is pressed
I guess basic java is the correct way for this. Nothing with the spigot api
Not quite. But kinda.
I need to check if a player is clicking a block for about 30 seconds. If they are do blah blah shoot of a firework for example.
If not then don't do anything, they must be holding right click on the block for 30 seconds.
SwingUtilities.isRightMouseButton(MouseEvent anEvent)
Returns true if the right mouse button was active
Vinex schedule a repeating task?
Maybe I can try it(plugin example), but you need to wait, because I gonna sleep xd
That's a bummer. Thanks though.
I can easily detect if they stop holding right click my part is, I need to detect if they held right click for 30 seconds.
If youโre in the Bukkit API use a BukkitTask repeating 30 times?
1run/second
If it gets up in 30 it checks ...
Or just make 2 tasks and compare
anyone know how I can get this to work? if (!(event.getInventory().getContents().equals(inv.getContents()))) return; event.setCancelled(true);
!Arrays.equals
thanks lol
I was curious what do you guys use to listen to packets? (Specifically server & client side) I couldn't get ProtocolLib to work.
I use ProtocolLib
I've tried but I failed to listen to the packets for some reason.
Can you post what you've tried so far?
I use my own packet handler that hooks directly into the server without reflection or that BS
But not everyone can do that so protocoollib is the way to go
Ok flex on us like that...
Before I proceed, can all packets be listened to, and canclled?
I tried listening to BlockBreakAnimationPacket and tried cancelling
and debugging still d idn't display an error or do anything 1 second.
Yes
Okay.
do you have any code Nerm?
It was a few a days ago but I'll do a mockup 1s.
private final PrisonPlugin plugin = PrisonPlugin.getInstance();
private final ProtocolManager protocolManager = this.plugin.getProtocolManager();
public ArmAnimationPacketListener() {
this.protocolManager.addPacketListener(new PacketAdapter(this.plugin, PacketType.Play.Client.ARM_ANIMATION) {
@Override
public void onPacketReceiving(PacketEvent event) {
event.setCancelled(true);
}
@Override
public void onPacketSending(PacketEvent event) {
event.setCancelled(true);
}
});
}
Well, obviously packet will only every trigger the event in one direction
so if I swing will it still be called?
That should work assuming you are creating new ArmAnimationPacketListener()
I'm assuming getProtocolManager is just returning ProtocolLibrary#getProtocolManager
^
I'll try it once more.
Hey guys, how do I delete a map from the game?
final WorldMap worldMap = (WorldMap) MinecraftServer.getServer().worlds.get(0).worldMaps.get(WorldMap.class,
"map_" + p.getInventory().getItemInHand().getDurability());
I have this, but how would I remove it so my world file doesn't get to large?
Yeah
Alright
How can I check if a click event was a Middle Mouse Button? sorry for the engrish I'm tired
There should a ClickType enum.
๐๐ป
The packet seems to be displaying now, but I'm guessing other players can't see it? (since I did cancel it)
that would make sense
Is there a way to redirect a player to another server which is not part of the own network/bungeecord?
no, because the target server needs to be offline mode
Don't need to be a bungee, lets say jusg from spigot to spigot. Make the launcher connect to another server
"Just" lol
There is no save way to make that happen
You want firewalls and all kind stuff in between to prohibit such connections
Yes
Oh yes, optifine, violating mojangs rules est 2012
Lets praise the message digest algorithm 5
XDDD
Well, they allow it to happen ๐
Well they're aware of it I'd assume? They're not dumb?
OptiFine's obtained such notority over the years I'd assume a staff member running the rules @ Mojang are aware.
If not ๐คท๐ปโโ๏ธ
Yes, they are aware, but it's not easy to handle something like this
What rule are they violating if you don't mind me asking?
What do you think?
I'm not too familiar with there ToS and Privacy Policy; my guess would be selling?
Selling itself is fine
It's just that there is one thing mojang never allowed to be sold and never will
Capes?
Yes.
Even if it's client-based?
Fair enough.
Could http://www.curseforge.com/minecraft/mc-mods/server-redirect do the trick?
Possibly, but I'm not sure there's a way to hook and verify they have that mod in there to connect
via. Channels etc
There is no good way to send players around without a proxy currently
Requiring a mod for something a properly setup proxy could do without a mod is dum
The idea is not using a proxy at all
so offline-mode based servers without a bungee?
Online-mode
Well, you can't without a client mod
I know
And requiring a mod is dum
Yea.
Sad there is no different way
So proxy is all you have
Or a way at all without client modification
Not familiar with Networking, but Sockets wouldn't event work would it?
It's way better than exposing your backend servers anyways
Dafuq are sockets supposed to help here? All this obviously uses sockets
You need a way to tell the client "connect to this ip now" which isn't available without modding that feature in yourself
Can I redirect from bungee to another extern bungee network?
I thought about how is there no serverlist on a server with actual portals to the servers. Now i know why
Thats why I ask these specific questions
Caused by: java.lang.IllegalArgumentException: Packet of sender CLIENT cannot be sent to a client.
Anyone care to explain this to me ๐ ?
Rather sent to whom exactly?
The server ^^
so stream through all online players and send it to them? or am I just dumb..
No that would be sending to the client
You don't need to send that packet, you only need to intercept packets the client send
For that type
What are you trying to do?
Basically when they punch a block remove progress.
Basically going step behind cancelling block-breaking.
As if they were in adventure mode in a way? But like when they punch it cancels it.
Mmh, not actually sure how that works, I think the client predicts all kind of stuff here
Would the server be capable of declining such things?
Rather than cancelling I was trying to set the DigProgress
to 0 each time they dig if you feel me.
Client will still attempt to start digging but cancel when it processed the ack
Iirc the block break animation is only send to other clients, not sure
I've got a gif of what I mean.
But yeah, I guess you could try sending that one too
Am I allowed posting GIF's?
But you really want set the ack to cancel
I know what you trying to do
You just lack experience with the protocol
^
Sadly
But I never give up.
So how would you necessarily modify Client-based wrappers then if you can't send them to the client?
are you trying to not show the player breaking a block?
Correct. An example of this below
https://gyazo.com/fead2c3542e62344756e4c678fd4e970
They mine, 0 progress.
You don't need to touch client packets
You want to intercept the digging packet from the client, cancel it and send back an ack with cancel and maybe a block break animation with 0 progress
Just curious, what's ack mean?
Acknowledge
I could just
Packet id is 0x08
Damn
real quick I never fully learned maven, what's the diff between a repository and a dependency?
more specifically, what does a repository do?
Repo is where dependencies are fetched from
Repo is the storage container no?
how does maven know which storage container to use to grab the dependency?
It doesn't
so how does it get it then?
It just tries everything
ah
And stores where it found it
that seems like a poor system
It works ๐คท
Better than one central repo
Like npm
And well, maven does have a central repo you can use
I have my own repo, I only specify that in my poms, and proxy all other repos there
nice
another small question
I've found that I don't need to override onEnable, it works either way
like the annotation
It still overrides
@Override
public void onEnable() {
}
is the same as
public void onEnable() {
}
yeah I never understood how that works
And the annotation is only for increasing readability
is that how it always works?
In that way we donโt need to look into the superclass to see what methods got overridden
Certainly annotations can be used for just more than readability but it was primarily made for that though.
I think Override annotation was also mainly introduced because people were writing their methods mispelled from the parent classes
with it it tells you without compiling if the method respects the one in the parent class
@torn robin if you want to use the code from the super method you can simply call super.method() in the subclass
as in you're trying to override a method that doesn't exist
what is the super method of onEnable? nothing?
itโs empty
So no need to
Letโs say youโre working with abstraction that might come handy then
There are many other annotations that help readability
Indeed
Actually I think some also help the performance
but I can't confirm this
like @FunctionalInterface
Yeah idk if it helps performance or just classifying the @interface as that
I was able to block the BlockBreakAnimation packet from being sent to other players but I can't figure out how to prevent it from showing up on the player breaking the block itself
i think thats just another client side feature..
as the server seem to only register the left-click being pressed once,not if its still pressed
I think breaking the actual block is client side
im wondering how i could change Compatible FML modded server to Vanilla server in bungee?
Can anyone help to me?
I will a Minecraft Spigot Server on my Pc and i cant this dowload from craftbukkit
What is that
is this a site?
i'll send it as a pic
I cant help you i am player of mc
well idk
I dont know what that is
@ember solar source code?
can anyone help me?
paste it in hastebin or pastebin
@stuck goblet what are you trying to download?
Spigot
You cannot download spigot directly
For a pc server
are you using BuildTools?
on 1.12.2
Read through that please Simi
its recommended to use BuildTools instead of downloading it directly!
What can i do whith build tools
just run java -jar BuildTools.jar --rev 1.12.2
it is expected not recommended
dw i fixed my error
๐
oh right heh. sorry lol
any answers?
what was the question?
im wondering how i could change Compatible FML modded server to Vanilla server in bungee?
copy and paste
How can i create an minecraft server on my pc???
what's not compatible Sketch? Worlds?
@stuck goblet https://www.spigotmc.org/wiki/buildtools/
- Download BuildTools
- run it in CMD Prompt with
java -jar BuildTools.jar -version 1.12.2
Thanks
or do that ^
yeah
I don't have that much experience with Bungee/FML but I doubt you'd be able to convert that easily
?kick @forest cobalt
๐ข Kicked peppis#5783
oh alright. that was off topic :p
Edit this to change the output of the command!
only admins can do that.
Ok
is there a way to make a block not being removed after a time? E.g. when I manually set a flower on top of a sand block, it will be removed after ~10s (just pops off, because its an invalid block) - is there a way to make this persistent? I looked online and someone suggested to set tickspeed to 0, but this is not an option for me, is there something else im missing?
@frigid ember I meant with thats not an option for me as in: I cannot go that direction as it disables a whole lot of other game elements.
its probably one of your plugins.
how do i make it so it doesnt show the world im in when I type in chat
nvm i fixed it
Luckperms: how do i give players permission to do /gamemode survival and /gamemode spectator?
@everyone
lmao
have u searched xd
https://github.com/lucko/LuckPerms/wiki/Usage#getting-started
https://bukkit.gamepedia.com/CraftBukkit_Commands
/lp group <group> permission set minecraft.command.gamerule true
sooo im trying to make this
converting the argument to int but it gives out the error how shall i be doing it so it goes the right way?
Integer.parseInt
ok lemme try that out
oh dont relate sharpness and durability xD just didnt find sharpness much fast in the suggestions
that worked very well thanks!
if you just implement tabcomplete its fine I think for your users
then they can try stuff really quickly
you dont have to rename every enchantment haha
ty for suggestion will do that!
what you maybe can in addition, is indeed do tabcomplete, but add your "custom" elements to it which are aliases :)
so if user types SHARPNESS it will be replaced to DURABILITY :)
i wont lie but im just learning tab completion
but i think ive found out how to do tat too^^^^
I'm making block queue system for placing massive amount of block. Should I use stable X blocks per X ticks or make it depends on TPS?
Basically the queue place X blocks each X ticks and if queue is still in processing it's not continue until process finish.
So what do you think about it? Should I use like it or make in another way?
Example code;```
new BukkitRunnable() {
public void run() {
if (inQueue)
return;
inQueue = true;
int limit = 0;
while (true) {
Block block = queue.poll();
if (block == null) {
inQueue = false;
cancel();
}
//PLACE BLOCK
limit++;
if (limit >= 100) {
inQueue = false;
cancel();
}
}
}
}.runTaskTimer(X, 0, 1);```
How can you set worldborder?