#help-development
1 messages ยท Page 1354 of 1
then use the other then lol
'' just means character literal. Confusing which needs to be used sometimes
bot.getGuildById("696626150553681951").getTextChannelById("826840223195070474").sendMessage(s.replace("s/\\x1B\\[[0-9;]\\{1,\\}[A-Za-z]//g", "")).queue();```
so this would be good?
god, leaked my discord id's
I will hack you ofc
please no :(
xdd
my server only has like 30 people, idk if that's worth it
that reminds me of the time the spigot people took over some malicious persons discord because they leaked their id stuff
anyways moving on....
thats just channel id's and stuff, idk if that is even bad if leaked
i mean it's not a bot token or smt
you need to create a pattern regex object I think, unless replace detects that as regex which I doubt
ofc no one is going to do anything here, i think the ppl who is here is just cuz needs to solve plugins problems
nobody knows
ikik
technically I could be sleeping under your bed right now
i mean... conclure looks kinda sus tbh
lmao
technically you wouldn't fit there
thought the pfp of my doggo could neutralize it a bit
if its a single character you need to replace use replaceAll as it takes a regex
@ivory sleet to be fair, all that means is either we need to be concerned for your safety or theirs, doesn't really indicate who though lmao
yeah indeed
anyone know the best way to go about adding fake players to the tab menu? seems like there is little to no documentation on this for 1.16.5
it isn't a single character, its ANSI control characters being replaced which the regex I gave will catch them.
leap arguably packets
that cute doggo kinda does a bit
k
protocollib?
but not that much, that i would trust you :/
hmm you'd only be sending packets so you could use raw nms I guess
if I switch to when my dog was a puppy?
well
yeah
thats oddly specific
yeah, i am specific
figured so much
not that hard to hook into the packet stuff to do this @barren locust you can use protocollib for this, but that is quite a large library to depend on for something so small and there is plenty of examples or their used to be on hooking into the packet stuff especially for the tab menu.
But you can definitely use protocollib for this. To identify which packet you need, just use https://wiki.vg
these are worthwhile considerations. I think I'll probably use protocollib since I suspect I'm going to need it for other things anyway
ty
Anyone know about bungeecord schedulers?
Its not that different from a regular ScheduledExecutor. What do you want to know?
DId you see this message?
I just need to keep spamming that title or something when the player is in limbo for being AFK.
Because at the moment, its diapering after a few seconds of being auto AFKd.
What exactly is your 'limbo'? A whole server?
Yeah bungeecord treats it as a regular backend.
Then i would just schedule one runnable that sends a title to a specific group of ProxiedPlayers. You can just add them or their UUID to a Set and frequently send them title messages.
Just make sure to clean the Set when they change the server or quit. getProxy().getScheduler().schedule(...);
@quaint mantle why are you bothering with a plugin that kicks for being afk, and then proceeding to override that ? o.O
Can I check when the player is moving through the proxy?
All packets are tunneled through the proxy. So theoretically yes. But why.
Hm, well In that case, I have no idea how I'm supposed to do that XD
Until I can learn how to listen to the packets through a bungee plugin, why can't I just check if the player is in limbo and then spam the title?
You can do that. I thought you meant physical movement.
There is an event for when a player changes the server.
How about this? ```java
if(p.getServer().equals("limbo"))
Yeah... no.
For one getServer doesnt return a String.
And then its just inefficient.
Wait what does it return then?
But what do you mean by 'the Server'? Is that the name of the backend defined in the BungeeCord config?
No its the Server object. It extends Connection and represents a destination.
Ah okay
Is there any way I can get a string of the server they are connected to then?
Yes
BungeeCord is a little bit more complex than writing Spigot plugins. And it looks like you are not even familiar with some of the Java basics.
So i would recommend you to write at least one or two more Spigot plugins and get familiar with the idea of proxies before you jump into writing
more stuff for BungeeCord.
And this will def help if your IDE is crippled ^
guys, i need help, im trying to update everyone's scoreboard everytime a player joins
i placed it onplayerjoin event but it is only updating the joined player
you have to update it for all players. Bukkit.getOnlinePlayers()
wdym
loop over all online players and update their scoreboard
that ill not lag the server?
unless you are dealing with hundreds of thousands of players, no
which is something hypixel doesn't even have
lol
okok if u say so
i didnt understood the loop xd
i made this but ik it isnt right
for(int cnt1 = 0; cnt1 < getServer().getOnlinePlayers().size(); cnt1++){
playersOnline = o.getScore(ChatColor.WHITE + "Players: " + ChatColor.GOLD + getServer().getOnlinePlayers().size());
playersOnline.setScore(5);
}
for(Player player : Bukkit.getOnlinePlayers()){
}
or Bukkit.getOnlinePlayers().foreach(player ->{ }
Bukkit.getOnlinePlayers().forEach(player ->() {
//code here
});```
Zoon beat me to it
dammit auto mod deleting my messages
i did this and it returned an error "Cannot resolve method 'foreach' in 'Collection'"
its forEach not foreach
i just typed on discord
so formatting wasn't gonna be right
Bukkit.getOnlinePlayers().forEach(player -> {
});```
then i paste this inside or do what? ```java
Score playersOnline = o.getScore(ChatColor.WHITE + "Players: " + ChatColor.GOLD + getServer().getOnlinePlayers().size());
playersOnline.setScore(5);
that doesn't look right to me
are you using one scoreboard per player or the default one? or a custom one?
i think im doing per player
in particular: o.getScore(ChatColor.WHITE + "Players: " + ChatColor.GOLD + getServer().getOnlinePlayers().size()); as I don't think that string is something that it will accept as valid.
it works on scoreboard
eh? But I'm reading about scoreboard in spigot and it doesn't take arguments?
when a player joins, loop over each player, get their scoreboard and update it
it is taking arguments
he's fetchign the score not a scoreboard. he should already have the scoreboard as 'o'
IDK I'm just referencing this in the javadocs: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/scoreboard/Score.html#getScore()
no, the objective variable is o
I need to spawn an entity, and keep track of that entity so when it dies i can change its item drop
How do i do things every X secs
Several ways to approach this. You can use the EntityDeathEvent or extend the NMS entity.
How you do that also depends on your specifications.
Are the drops defined when the entity spawns? Are they correlated to external conditions like who killed the mob or what biome the mob is in?
for example i want to do automatic messages every X secs
With a scheduled task. Look at the BukkitScheduler
AAAAAAAAAAAAAAAAAAAAAAAAA. i think im just gonna figure out how to use NMS to add an NBT
Zombie bossEntity = loc.getWorld().spawn(loc, Zombie.class);
NBTTagCompound tag = new NBTTagCompound();
((CraftEntity)bossEntity).getHandle().c(tag);
tag.setBoolean("isboss", true);
i just dont know how to check if a entity ahs that NBT
cause there are no NMS documentations
and im using 1.12
Why dont you just use its PersistentDataContainer? Thats basically NBT data.
Oh 1.12
yea..
Cannot resolve symbol 'getScheduler'
Where do you call that from?
Its a static method from the Bukkit class
outside of methods
if i could figure out how to use this https://www.spigotmc.org/resources/nbt-api.7939/ it would probably be easier
it gives you the tutorial in the readme
are you talking to me?
yes
Ok so if you have some specific type of mob then you could have something like a Map<String, DropTable>
Then when any mob dies you check its tags and see if it has some entry that looks like
"BossTag":"MegaCreeper" or "BossTag":"ZombieKing" or whatever.
Then you simply get the drop table from your map and set the items from in there as drops.
Thats the crude approach.
well i set the NBT right here
NBTTagCompound tag = new NBTTagCompound();
((CraftEntity)bossEntity).getHandle().c(tag);
tag.setBoolean("isboss", true);
i just have no idea how to read it
I just need someone who knows 1.12 nms
i did this ```java
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
}
}, 20, 20)
if some1 could help me i will be happy
can someone just show me how to use this?
if its a library, i have no idea how to use it, and if someone could show me it would be great and i could use the knowledge in the future ๐
Do i litterally just add it as a new class in my project?
i just kijnda threw it in
and
i think it works?
I'm just gonna ask again cause I found out the issue, I just don't know how to fix it. I "marked" the two things that I don't know how to fix with a comment
public static ArrayList<Player> ChestOpen = new ArrayList<>();
public static ConcurrentHashMap<Player, Integer> ChestsOpen = new ConcurrentHashMap<>();
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (e.getClickedBlock().getState() instanceof Chest) {
e.setCancelled(true);
if (!(GlobalState.isState(GlobalState.WARMUP) || GlobalState.isState(GlobalState.IN_GAME))) {
return;
} else {
if (ChestOpen.contains(p)) { //This one doesn't work <<<-------
e.getClickedBlock().setType(Material.AIR);
if (!ChestsOpen.get(p).equals(thing.getInstance().getConfig().getInt("chests-per-player") - 1)) { //and same with this
int toAdd = 1;
int newChestsOpened = toAdd + ChestsOpen.get(p);
ChestsOpen.put(p, newChestsOpened);
} else {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', MessagePrefix.messagePrefix() + "&7You have already opened " + thing.getInstance().getConfig().getInt("chests-per-player") + " chests!"));
}
}
}
}
}```
- variable naming conventions
- use ChatColor please instead of the translate alternate color codes or make a method for it to make it not messy
- why ConcurrentHashMap? You have to have reasons for using the data structures to use
- is static necessary for the variables? Are you caching them as constants?


@paper viper ?, thats not the issue, I have it as HashMap now either way, yes
yeah but thats not why it doesnt work
well then just fix those things first
cause those are the basic stuff
you also haven't described "doesn't work"
any error/exception?
- never store the player object
Use UUID instead
WeakHashMap ๐
for the Player
Or actually you could use IdentityHashMap
Because it has faster lookup
And then ofc erase players when they log out
wait
Hmm yeah
ig
still didn't really help the issue: if (ChestOpen.contains(p))
๐
I don't get any errors but the issue is that if (ChestOpen.contains(p)) literally just doesn't work
like bro
have you debugged the contents of ChestOpen
have you changed the p in the check to p.getUniqueId? Since you've changed it from Player to UUID you need to change what it's checking for to check for the UUID instead of just Player
yes, all of the p's
and I'm not sure but players not being added to the arraylist might be the issue?
faith ๐
๐ฅฑ
there ya go
debug it and see if the uuid is even in there
thats probs your problem
Hello, I want to know how to let all the classes know if something happens in a different class. Is there a way to broadcast a message to all classes or something. Like for example if a player dies. I might want to tell a diffferent piece of code in another class
kind of like functions
whats your usecase
or just make an event yourself
thats pretty much what the event system is
but it depends on what you want to use it for
well i have a thing that if the player sleeps i want them to loose some of their hunger due to it just being a new day
Maybe inject callbacks
so I thought I could put the hunger in one class and the sleeping in anothyer
you could do that all in one event
Now I know this is stupid but in scaratch there is a thing where you can kind of send a message and ave seperate code that listens for said message
Is there a way to do that in this
or kind of like that
you call the function in another class
di is dependency injection
@paper viper
wot
Hi
Hola
@paper viper howโs life?
public class MyClass1{
public void myFunction1(){
}
}
public class MyClass2{
MyClass1 myclass = new MyClass1();
myclass.myFunction1();
}```
good wbu
Not di but ok
was not an example of di
@paper viper ah Iโm good
Is this 4 me
It jsut shows how you call a function of another class from somewhere else
depends on your project setup
I'd really recommend learning a bit of OOP it goes a long way in plugin development
public class MyCustomEventHandling {
private static final List<MyInterface> INTERFACES = new ArrayList<>();
public static void registerEvent(MyInterface myInterface) {
INTERFACES.add(myInterface);
}
public static void callEvent() {
INTERFACES.forEach(i::doMethod);
}
}
@deft sedge
ok
me.emils.TIMV.mechanics.ChestOpened.onPlayerInteract(ChestOpened.java:44)
is returning null
So I guess it was what I thought? if (ChestOpen.contains(p.getUniqueId()))
show code
nvm ima send the more updated one
private List<UUID> players = new ArrayList<>();
public List<UUID> getPlayers() { return players; }
public static ArrayList<UUID> ChestOpen = new ArrayList<>();
public static HashMap<UUID, Integer> ChestsOpen = new HashMap<>();
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
ChestOpen.add(p.getUniqueId());
if (e.getClickedBlock().getState() instanceof Chest) {
e.setCancelled(true);
if (!(GlobalState.isState(GlobalState.WARMUP) || GlobalState.isState(GlobalState.IN_GAME))) {
return;
} else {
if (ChestOpen.contains(p.getUniqueId())) {
e.getClickedBlock().setType(Material.AIR);
if (!ChestsOpen.get(p.getUniqueId()).equals(TIMV.getInstance().getConfig().getInt("chests-per-player") - 1)) {
int toAdd = 1;
int newChestsOpened = toAdd + ChestsOpen.get(p.getUniqueId());
ChestsOpen.put(p.getUniqueId(), newChestsOpened);
} else {
p.sendMessage("too many chests message thing here yes yes later");
}
}
}
}
}
my eyes
so much is wrong/bad practice in this code
dude use naming conventions
done.
somewhere in your other code you are doing WhatEverClassThisIs.ChestOpen = null; or some sh
no.
yes.
actually can you just send the entire class instead of making me wonder where line 44 is?
chestsOpen.get(p.getUniqueId()) == null
https://paste.md-5.net/gawebihevu.xml
shading with this gives me this error upon loading the plugin: https://paste.md-5.net/raqixeluvi.bash
what I said from the start before all the debug thing but yeah I know but still not sure how how to fix it
if (chestOpen.contains(p.getUniqueId())) {
thats why you name your variables better
chestOpen.add(p.getUniqueId());
if (e.getClickedBlock().getState() instanceof Chest) {
you dont even see if its a chest first
int toAdd = 1;
int newChestsOpened = toAdd + chestsOpen.get(p.getUniqueId());
yes, lets make a final local variable with a value of 1
remove toAdd
okay removed it...
._.
?
I removed it but I still need a way of counting the amount of chests?
int amount = 0;
void a() {
amount++; // Increase amount by 1
}
void b() {
amount--; // Decrease amount by 1
}
I want to make code where people can type a command like for example /sleep <keyword> The keyword can be anything but if two of any players type /sleep and then the same keyword, it get's both of the player's names and just stores them to a var
k?
is that a thing and/or is there a way to do it
well problem is that I'm making a minigame and it has to be a command
it's not real mc sleeping
How does that matter?...
it's a long story
i'd be happy to say
basically i'm making a thing where there are teams and u have to survive on an island
just on the command add em to the map
and everyday you loose one day of thirst and whatever else
i need to have it where two people agree to the "sleeping" bc there are partners in the game
Ik it's confusting
Why not store the partners and then just have the command
Instead of needing some keyword
well becaue this is gonna be more confusing
i'm making this for a school calss
and an entire grade has to play this game
Unless you are a beginner at java this isnt hard at all
and the taecher is not gonna buy 100 mc accoutnts
so i have to have a select few and I can just store data in a book
i'm not that beginner I can understand programming
public class IntHolder { // Object, pass this around
public int sleeping = 0; // turn this into getters and setters
}
for me it's more the actual how you do things
@quaint mantle still having issues with it not going through if (chestOpen.contains(p.getUniqueId()))
So basically you want to make it so if people execute a command to sleep, and if the keyword matches one already made send a request to the original person or whatever correct?
So thats easy, you are overcomplicating this some how
probably ๐
Map<String, Boolean>
On command
Check if map contains keyword
- if not: add a player unique object into the map with a key of the keyword
- if so: get the player in the map with the key of the keyword and send the request
ok
Its java, everything you tell it to do does it
k
Sounds like a more complicated set with .contains
yeah i didnt read the question fully
it sounds like he just wants Set<String>
i also need to get the username of the two ppl who sent the keyword if it matches
im gonna make a somewhat-close example
If you look in the psuedo code I sent, I said to include a player unique value
ok thanks for taking the time to help ๐ Sorry if i'm bing slow
k
lol
oof forgot I cant use external emojis in here
Map<String, UUID> map = new HashMap<>();
void onCommand(UUID playerUUID, String arg) { // just an ex. lol
UUID uuid = map.get(arg);
if (uuid != null) {
// do stuff
map.remove(arg);
return;
}
map.put(arg, playerUUID);
}
@deft sedge hopefully this isnt a spoonfeed
just tryna give you an idea
ok thanks
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Core: Com
pilation failure: Compilation failure:
[ERROR] /E:/core/src/main/java/me/zoibox/core/core/Core.java:[5,19] cannot access dev.morphia.Datastore
[ERROR] bad class file: C:\Users\wsmit\.m2\repository\dev\morphia\morphia\morphia-core\2.1.4\morphia-core-2.1.4.jar(dev/morphia/
Datastore.class)
[ERROR] class file has wrong version 55.0, should be 52.0
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
[ERROR] /E:/core/src/main/java/me/zoibox/core/core/commands/misc/gamemode/CreativeCommand.java:[12,1] cannot find symbol
[ERROR] symbol: static setGamemode
[ERROR] location: class
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
your ide shouldve stopped you from even running the build
show core/src/main/java/me/zoibox/core/core/Core.java
and dev.morphia.Datastore
makes sense
we told you what was wrong
yeah and how do I fix this
I tried switching to java 8
didnt fix it
so I went back to 11
didnt fix it
55 iirc is 11 and 52 is 8
correct
what is iirc?
If I recall correctly
java.lang.IllegalArgumentException: Team already exists in this scoreboard
``` Not exactly why the team is just empty
bro
can someone help me... please.
.
if (event.getEntityType() == EntityType.Zombie)
If that field was ever null Iโd have some questions
lol
@quaint mantle I did the part wheryou store the map
but how do I check a map for a specific kdywork
like if it's already there
containsKey(keyword)
thx
and then how do I get the uuid of the player listed with that keyword
if i find an equal one
Use Map::get . You'll get null if no value is associated with the key.
ok thanks
for (OfflinePlayer players : Bukkit.getOfflinePlayers()) {
Player player = players.getPlayer();``` Could someone help me? the `player` variable is returning null.
Because they aren't online, so there is no Player object for them
You're not the only OfflinePlayer
How would I convert an offlineplayer to a Player?
Iirc you can check isOnline
I want to set something for all of the offline players though.
@real vapor so if the arg has the keyword do i do Map::get arg?
or anyone else who wants to answer
ok
Is the only way to get experienced in development like doing it or is there another functional way
Generally you get experienced in something by doing it
Thatโs kind of what the word means
True true
Why is Player#getUniqueId() throwing a NPE
Is player null?
Yes
this is an a command executor:
Player playerSender;
if(commandSender instanceof Player) {
playerSender = (Player) commandSender;
} else {
return false;
}
/* some ... stuff */
trailHandler.setSlotEnabled(playerSender.getUniqueId(), pickedSlot, offOrOn);
And this is in an event listener:
//Event is PlayerInteractEvent
Player sender = event.getPlayer();
if(event.getAction() == Action.LEFT_CLICK_AIR) {
if(!arrowPowerManager.getActive(sender.getUniqueId())) { //NPE thrown on this line
return;
}
}
is throws NPE's from both of those statements occasionally
but I noticed it mainly rn when I ran the command executed by the above executor
Can I see one of these errors?
and it threw an NPE when I ran it
31.03 20:59:41 [Server] ERROR Could not pass event PlayerInteractEvent to TanoshiCore v1.0.0
31.03 20:59:41 [Server] INFO java.lang.NullPointerException: null
31.03 20:59:41 [Server] INFO at com.chasemw.tanoshicore.eventhandlers.WeaponClick.onClick(WeaponClick.java:31) ~[?:?]
Should run a newer java version and enable the improved NPEs
for some reason IntelliJ isn't working with Maven
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.msws</groupId>
<artifactId>Food</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
that's my pom xml, but no spigot imports are registering
there aren't any errors that I can see
It would be cause player is null no?
Add a check for it?
wdym "player"
as in the sender variable?
thats defined by event.getSender(), which is a playerInteractEvent
so why would event.getSender() be null, and what am I supposed to do if it is? don't PlayerInteractEvents only execute when a player interacts>
Hello I am trying to make when a player kills a cow he dies and the cow dosent drop anything! (Killing Cows is illigal)
arrowPowerManager is null
so still, why would getPlayer be null @candid galleon
it's probably static or you never initialize it
no its initialized
can you send the code?
?paste
it's initialized in the main class, and passed via the constructor of the WeaponClick listener
can you send the class still?
the one that has the NPE
lmfao
and the main?
so it is null
It's not static so it sets it on the first instance created but not the next few?
Cause when OnClick is called it makes a new instance
I bet if you make private final ArrowPowerManager arrowPowerManager; static it will work
weirdly enough this code actually works
I thought it didn't?
it throws the NPE and spams my console, but it fires the arrow
can we see the main class?
it need to be assigned in my main class though
yeah one sec
But if a new instance is created via the OnClick method then it will be null
that's not how java works Mike
onClick is not static
@candid galleon
Contents of my onEnable method (main class)
https://paste.md-5.net/ilacolofoy.coffeescript
idk why it says coffeescript
whatever
its java
When a new instance of WeaponClick is created the OnClick event will be fired and arrowPowerManager will be null
how is it going to create a new instance of weapon click without passing the arrowPowerManager into the constructor
it doesnt
there is only one weaponClick object ever, and it's the one I initialize in my main class
when I pass it into the event registrar
that code should work, are you sure your server is running the most recent build of it?
might want to check any duplicate jars too
Ill make sure
I'm pretty sure I'm right lol
please elaborate when a new WeaponClick instance is created??
Every time the OnClick event is called
so are you saying it creates a new arrow power manager every single time
and how is that
This is the only time an instance of weaponClick is ever created
getServer().getPluginManager().registerEvents(new WeaponClick(arrowPowerManager), this);
ever
spigot literally just goes through the register and executes the events from the passed object
it doesn't create a new instance of it?
ok i cleaned out all of the plugins and stuff
this is thrown when i click, still
31.03 21:23:15 [Server] ERROR Could not pass event PlayerInteractEvent to TanoshiCore v1.0.0
31.03 21:23:15 [Server] INFO java.lang.NullPointerException: null
31.03 21:23:15 [Server] INFO at com.chasemw.tanoshicore.eventhandlers.WeaponClick.onClick(WeaponClick.java:29) ~[?:?]
as before
line 29 is:
if(!arrowPowerManager.getActive(sender.getUniqueId())) {
23*
Doesn't include imports
I didn't send the imports
id try printing out if the apm is null
if it is null then at least you know the problem
it says false
System.out.println(arrowPowerManager == null);
prints false
@candid galleon for reference, this is apm: https://paste.md-5.net/cumokijije.cs
ig check player then
OH
LOL
yeah that APM class helps a lot
you're returning a Boolean which is an object, meaning it can be null
change that to boolean, and return false if the map doesn't contain the id
That'd do it. Is the player ever inserted into the ArrowPowerManager#powerActiveForPlayer
better yet change that map to a Set and return true if the set contains that UUID
no need for a map
so this should be better?
public boolean getActive(UUID id) {
if(powerActiveForPlayer.get(id) == null) {
return false;
} else {
return powerActiveForPlayer.get(id);
}
}
public Set<UUID> powerActiveForPlayer;
public ArrowPowerManager() {
powerActiveForPlayer = new HashSet<>();
}
public void setActive(UUID id, boolean active) {
if(active) {
powerActiveForPlayer.add(id);
} else {
powerActiveForPlayer.remove(id);
}
}
public boolean getActive(UUID id) {
return powerActiveForPlayer.contains(id);
}
yep like that
id shorten the powerActiveForPlayer name and make it private
but other than that looks good
bad IDE
https://paste.md-5.net/ogozikimeg.cs
Okay so Im creating world flags now for each world, and for some reason when i add/remove flags the events don't update or anything! Any help is greatly appreciated!
Wait is there only ever one instance of this ArrowPowerManager? Why not make it a static final in some util class instead of having an Object
What?
Why would that be beneficial? I only want it initialized once, and in the place where all classes can access it
Also being able to modify it is helpful
In my main class is fine
I mean it doesn't need to be an object unless you're going to have multiple instances of it?
I have a Block and I am checking specifically if it is Material.WHEAT. What I'm trying to figure out though is how to find if it is fully grown wheat? I can't seem to figure this one out ๐ฎ
I would recommend using enums for the flags.
I have a feeling I need to getMetadata, but IDK what key I'm looking for
recommend what? @quaint mantle
get the Block's BlockState and cast it to Ageable
declaration: package: org.bukkit.block.data, interface: Ageable
Enums lol idk what happen there
i do use enums
@candid galleon thanks a lot! I was lost there for a bit not sure what to do. I appreciate the quick reply.
๐
i originally had it checking for the enum however it didn't work so I tried different options
I see. Your code looks fine. Yet to find an issue. Any error is console?
you shouldnt be repeating so much code imo
avoid when possible
none at all, and when i add/remove flags the config updates itself fine. Im so confused why i don't see any update though when i add/remove it player side
if (!new File("plugins/CherryAPI/worlds/" + worldName + ".yml").exists()) {
this.maxPlayersAllowed = getMaxPlayersAllowed();
this.worldFlags = new ArrayList<>();
CherryConfig.createFile("plugins/CherryAPI/worlds/" + worldName + ".yml");
CherryConfig worldConfig = new CherryConfig(new File("plugins/CherryAPI/worlds/" + worldName + ".yml"));
worldConfig.loadFile();
worldConfig.getConfig().set("name", worldName);
worldConfig.getConfig().set("maxplayers", getDefaultMaxPlayersAllowed());
worldConfig.getConfig().set("flags", worldFlags);
worldConfig.saveFile();
this.worldConfig = worldConfig;
} else {
CherryConfig worldConfig = new CherryConfig(new File("plugins/CherryAPI/worlds/" + worldName + ".yml"));
this.maxPlayersAllowed = worldConfig.getConfig().getInt("maxplayers");
this.worldFlags = WorldFlag.parseStringList(worldConfig.getConfig().getStringList("flags"));
this.worldConfig = worldConfig;
}
You could make this a method.
im not worried about my constructors at all @quaint mantle , im more focused on fixing the flags
Seems to be a event thing
First thing. Did you register the Listeners?
yeah sure did. the only time that i see the updates happen is when i reload the server
events work fine, they just don't update when i add/remove the flags
Oh wait
i thought about re-registering the events, but i think that would cause too much lag
Well I'm not sure. I had an idea but it wouldn't make sense
it would not work but can you put a println for this getWorldFlagStringList().contains(WorldFlag.NO_ITEM_DROP.getConfigTag()
okay
so
i inserted that code in the blockplace event, and changed the enum to match, and it returns false. HOWEVER the world does have that flag added, but it returns false instead.
Config was saved correct?
yes
it's as if it's opposite
so maybe i need to just put ! in front and go with it? xD
that did not fix it lmao
WTF xD
If you really wanted to. Print out what is in config so you can see if it has the flag.
oh!
okay!
i got it, so, it's retrieving an empty list XD
sooo, what the issue was it was retrieving the flags list as a string list (which it wasn't) and that's why it was empty. So i have to change the method when it retrieves the list to fix the issue
then it should be good
Perfect!
it was a good thing i went ahead and condensed my code too while i was waiting for your input now it should hopefully work
๐ฏ Glad to help.
alright, still no fix. The list is printing correctly though now and it is checking correctly. However the event doesn't want to work as soon as the flag is added/removed
File("plugins/CherryAPI/worlds/" + worldName + ".yml") stick this into a variable @quaint mantle
second, you are checking files incorrectly
it should this
File("plugins/CherryAPI/worlds/", worldName + ".yml");
notice I changed a + to a ,
yes and no
im still having my issue with the events not just updating
?
oh wait nvm
you don't have to, but helps with making it look nice/readable
also helps with not making a mistake for the same directory since you can have it defined in just one place
and I pinged the wrong peron @quaint mantle
sorry just woke up
@crisp iron can we see the code for the config update stuff?
public class NOITEMDROP extends ServerCherryListener {
public NOITEMDROP() {
super(worldName + "_NOITEMDROP", false);
worldFlagEvents.add(this);
}
@EventHandler
public void event(PlayerDropItemEvent event) {
if (getWorldFlagStringList().contains(WorldFlag.NO_ITEM_DROP.getConfigTag())) {
Player player = (Player) event.getPlayer();
if (!player.hasPermission("cherryapi.flag-override")) {
System.out.println("THIS WORKS RIGHT?");
event.setCancelled(true);
new OnlinePlayer(player).sendColorfulMessage(ServerAPI.getAPI().getBasicMessages().getString("itemdrop-disabled"));
}
}
}
`
}
add this debug
@crisp iron
lol you need a bang or a Redbull
I agree with you in aoviding duplicity where you can
as well
have a monster energy drink
just waiting for it to kick in
XD
LOL its like 10:28 way to late for me
is the worldmanager called WorldConfig?
called WorldManger
Looks fine to me. Can you add the debug and tell us if it works.
be nice to see where you set worldConfig? since you are complaining of configs not updating
He said it saves btw
^
Ok then what issue you having where you say events are not updating? o.O
@crisp iron ^^^^^^^^^^
so say i remove block place event, you still can't place blocks as if it didn't update. but then when i reload the server it's fine.
that doesn't really make sense. So you remove the event from your code for example right? And it still doesn't let you place blocks even though you are not touching the event?
exactly
I assume you are using a variable to check this?
or you just straight up commented out your code?
@crisp iron are you OPed on the server?
no
This sounds like a case of you updating your plugin and assuming that if you replace the jar, the server should have updated code. When in fact you need to restart the server because all class files in jar gets loaded into the server and doesn't update without some tool to force it to do so or just restart since you know everything unloads then XD
just so were clear, everytime that i've put the new jar in i've had to restart, im using maven so there really isn't any other way
so that's not the issue
Yes that is completely normal to do that. So not the issue then alright just had to make sure lol
be surprised in how many people assume their code should automagically update XD
yeah i'd see where that can be an issue
but like maven has a complete and seperate output
rather than looking at the itemdrop event that i have look at my block place event (that's what i've tested on the most)
is your project open source?
guess that works lol
that is an updated version of the class we've worked on
static abuse
well they don't abuse it like others do so I will commend them on that
i cannot lie, i've tried my best to avoid statics entirely
but sometimes i just slip up
Static is not a bad thing to use. You just gotta use it properly.
anywho, i realized that when i called for the list "getWorldFlags()" and then print it it doesn't update
so that's now an issue
it is the issue
https://paste.md-5.net/rapoyiqece.cs#L102 change this to have some checking to it
anytime you can possibly have empty lists/null's returned, have some kind of check to inform when this is possibly not what is wanted.
in fact
well heres the thing, it isn't returning null it's printing a list, but it's not getting the updated list from the config (idk why) cause there's where i pull it from
change that to reference your variable at top
well, you reference the variable flags in two different ways
so, maybe if we fix it in your code to be just at a singular place maybe that might fix it
i hate to doubt, but i really don't think its the issue
https://paste.md-5.net/rapoyiqece.cs#L102 you can move this to the top if you really wanted where you are declaring the object.
When removing metadata does the player actually need the metadata to try to remove it?
@storm tiger generally wise to put a check in place so you are not just running code unnecessarily
looks like removeMetadata already checks if they have it
sometimes it will throw a minor error if you are trying to remove non-existent metadata but it really depends how you are doing it.
https://paste.md-5.net/rapoyiqece.cs#L102
this should be swapped with the line above it
swapped exactly with which line
101
the one right above it
whether the file exists or not isn't relevant to the file Object. Should create your object first and then check if said directory/file it holds actually exists, create if it isn't.
https://paste.md-5.net/rapoyiqece.cs#L102 unecessary cast to player. Odd you have your own Listener object.
i go a bit further with it for the API to create customization
Well its not a typical thing to see most of the time ๐
it is fine you have your own objects like that if it makes things more convenient ๐
yeah i even have a custom command class
allows the ability to create your own help page
like for each command
btw I used the wrong line number earlier
it's "hella" advanced, not advanced, just much more convenient
my apologies, the line I was referring to was https://paste.md-5.net/rapoyiqece.cs#L196
but line 102 might be where your problems are at for the flags
whyyy does Recipe not have getKey
if i swapped the lines that your talking about it would just throw an error when creating / loading in new worlds
so, that method should reference your flags object that is up top. In the constructor where you initialize it is where you would update said object. To prevent accidentally NPE's you can go ahead and move the arrayList creation to the top so at minimum it will return an empty array if something calls for it too early
private List<WorldFlag> worldFlags = new ArrayList<>();
/**
* Returns world flags
* @return
*/
public List<WorldFlag> getWorldFlags() {
return this.worldFlags;
}
/**
* Initialize config
*/
public void initialize(String worldName) {
this.worldName = worldName;
this.permissionAccess = WorldManager.accessPermission + worldName;
this.worldFlagEvents = new ArrayList<>();
this.getWorldFlags().addAll(WorldFlag.parseStringList(this.worldConfig.getConfig().getStringList("flags")));
this.isLoaded = false;
this.eventsLoaded = false;
this.worldConfig = new CherryConfig(new File("plugins/CherryAPI/worlds/" + worldName + ".yml"));
if (!new File("plugins/CherryAPI/worlds/" + worldName + ".yml").exists()) {
this.maxPlayersAllowed = getMaxPlayersAllowed();
CherryConfig.createFile("plugins/CherryAPI/worlds/" + worldName + ".yml");
this.worldConfig.loadFile();
this.worldConfig.getConfig().set("name", worldName);
this.worldConfig.getConfig().set("maxplayers", getDefaultMaxPlayersAllowed());
this.worldConfig.getConfig().set("flags", WorldFlag.convertToConfigList(worldFlags));
this.worldConfig.saveFile();
this.worldConfig = worldConfig;
} else {
this.maxPlayersAllowed = worldConfig.getConfig().getInt("maxplayers");
this.worldConfig = worldConfig;
}
}
ok, contains all the fixes so as to use your getter, as well as removed the redundant creation of worldConfig object
okay im gonna try this
You have worldConfig up at the very top already declared, doesn't make much sense in the initializing phase, to create another worldConfig object. Mainly because you are wanting to set the global variable, not the method local one.
Should fix your problem since you had that duplicate worldConfig going on. The one in the method, was not updating your global one
but your global wasn't being updated because it was fetching from the config file which happened on startups
hence why restarting made it update
How come on toggle flight event if i cancel turn their allow flight off and flying off and give them a little push they just start going down
because the server updated their state since something interacted with them
like what though
the player object state. Server doesn't immediately make them fall because it isn't always checking if the block they are on is air or not until they start moving
since you pushed them, they moved
thus now the server checks the block under them and goes, oh yeah its air so start falling now
anyway to just like bypass that?
im setting velocity
so shouldn't it keep going up until the motionY is 0?
don't understand that last part o.O
yeah i dont either tired
but
its like im getting teleported down, but whenever i use like an ender pearl that sets velocity instead of throwing it the velocity works perfectly but once i check for them toggling their flight it just bugs and starts trying to teleport them down
so the ender pearl, is custom correct?
and instead of teleporting it sets a velocity?
testing now, i had a few NPE's but they are fixed
Ah my bad if that was my fault lol
yeah and it works fine when setting velocity, but whenever i set velocity after they toggle their flight it just teleports me something like that
still no fix
hmm something is setting off teleport event whenever doing that
yeah it's weird
That was really the only place where I saw duplicate object creation lol
make sure to remove these lines this.worldConfig = worldConfig; as well
not needed since you are just referencing a singular object and updating that. And everywhere else should be referencing the getter outside of the initializing method
@storm tiger it could be the fact that the player object is kind of in limbo when they are hovering in the air like that. If they toggle their flight, either toggle it back on before doing your thing, or do something to update their state first.
i have the code exactly like you suggested (with the exception of a few changes to fix the NPE's i was getting)
interesting, could have sworn that would fix your lists not updating properly o.O
I would start adding some debug messages @crisp iron
so after every thing you are doing manipulating the list in all your code just have it print out what it just did as well as what the list looks like.
im just going to use a hashmap
and store the list when the world is first initialized, then at the end save all the lists.
@wet breach
that could work. But I believe you should probably resolve the issue first before making drastic changes
not to bad of a drastic change honestly.
otherwise you won't gain the experience/knowledge in why it wasn't working to begin with
meaning if you encounter this issue again, you wouldn't know where to possibly start checking for problems since you didn't bother resolving a similar issue. However, it is up to you which you want to do though.
Just my personal opinion is all. Second it is good to get into the habit of being able to create debug messages too
this won't be the only time you encounter such a problem where it isn't obvious on the problem
Debug messages help you narrow down where an object isn't being updated properly so you know which methods are possibly responsible, instead of not having a clue since a lot of things touch it.
im using a packet listener for getting when the player moves but how would I make a way to get the players previous position?
the PlayerMoveEvent has a method of getting where they moved from
and another method to get where they moved to
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerMoveEvent.html#getTo()
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerMoveEvent.html#getFrom()
declaration: package: org.bukkit.event.player, class: PlayerMoveEvent
first one is the method for getting where they moved from. AKA previous location, second is to get the location where they moved to ๐
oh packet listener
why are you using a packet listener for this?
You are just going to have to keep track of the players previous positions yourself if you are going to go the packet route @outer sorrel which isn't really necessary since there is events that get triggered for this and API methods to help with it.
doing packet stuff
Ok
ill try to use the move event then
why does that mean you can't use the API?
theres no getFrom()
There is in the API
If you are going to try and use both the event and packets
then you will need to have your packet listener wait on the event to complete which there you would use a custom object that your packet listener can then use. Personally I would only use packets if its really necessary. Most of the time, it isn't always more efficient to just manipulate packets then to just manipulate events.
ok thanks
event.getClickedBlock().getLocation() == button.getLocation()
So, these are the same location, yet the boolean is still false. confusion
Oh no
Look at the operator again, then question your life choices
Spoiler: ||they are not the absolutely same location like == would suggest, they may differ in the memory location, == only checks for the memory location||
okay then
how can i check if the block that i clicked is the same block that im trying to refer to
presumably id use locations?
Seriously, have you used java before?
If only there was a method that does this, it's not like it's nicely named ||Object#equals(Object)||
There is absolutely no reason to be rude when I'm asking questions based around development, the entire point of this channel. Yes, I know Java and have been developing with it for the past two years. Simply put, I misread the first 'spoiler' you gave.
Basically, only use == for Enums, Integers, Doubles, Floats, Chars, Interned Strings (they are almost never interned), Shorts, Longs and a few other rare occasions, Object#equals(Object) should be used for anything but primitive types (in which case it will not even compile)
Thank you, that does help ๐ Sometimes I forget the difference
can anyone help me in #help-server ?
@alpine swan This is #help-development , not #help-server
Guys, im trying to do a database, should i do a local or one with sql?
SQL can be local, but it is recommended that the database should be as near to the server as possible (preferably on the same machine)
don't do most of that
Integer and other primitive wrapper classes have some instances cached, but not all
most of the time, using == for them is just as bad as using == for Bukkit Locations
I would need to look into that
yes, you would
But I am fairly sure that this hasn't blown up yet and I have worked with boxed integers for a while now
:thonk:
Ight, time to decompile some bytecode!
or just look at the documentation?
looking at bytecode is a terrible idea, as you might discover implementation details that can change in the future
even comparing Boolean instances via == is a programmer mistake
that was a fun bug to debug
declaration: module: java.base, package: java.lang, class: Integer
.code stack 2 locals 3
L0: ldc '1000'
L2: invokestatic Method java/lang/Integer valueOf (Ljava/lang/String;)Ljava/lang/Integer;
L5: astore_1
L6: aload_1
L7: invokevirtual Method java/lang/Integer intValue ()I
L10: sipush 1000
L13: if_icmpne L24
L16: getstatic Field java/lang/System out Ljava/io/PrintStream;
L19: ldc 'sssss'
L21: invokevirtual Method java/io/PrintStream println (Ljava/lang/String;)V
.stack append Object java/lang/Integer
L24: sipush 1000
L27: istore_2
L28: iload_2
L29: sipush 1000
L32: if_icmpne L43
L35: getstatic Field java/lang/System out Ljava/io/PrintStream;
L38: ldc 'sssss'
L40: invokevirtual Method java/io/PrintStream println (Ljava/lang/String;)V
they are the same thing, javac isn't that stupid
Basically, it auto-unboxes it automagically; while sure, it is an implementation detail, it can almost be guaranteed that it will stay that way because it would simply break too many applications otherwise
No, normal javac
This was written without any IDE
congratulations
Then disassembled via Krakatau
congrats, you reached the wrong conclusion though
So basically as long as only one operator is primitive it will auto-unbox
yes
Is it possible to generate a method when you annotate something?
yes
Hey how do I make a specific mob invincible/not killable
Or would I need an interface
It probably has to do that I only work with small numbers I guess, but I suppose it is good to know for the future
How tho
Hello can someone pls help me
Hey how do I make a specific mob invincible/not killable
@quiet ice yeah you might be landing in the integer cache https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Integer.java#L1003
It doesn't show you how to generate a method
It shows you the basics of annotation processors
that cache is literally documented and said documentation been linked here
yes it does
That is JVM specifics though
what
It is best to know it for use if you look at the disassembled code (two boxed integers use acompare, if one is not boxed then it uses icompare instead)
what point
Alternatively you could look at how Lombok does it @weary geyser
lombok is a mess, dont copy lombok
Apologies, I misremembered what that article is about
I mean, it works
/summon mob ~ ~ ~ {invincible:1b}
That articles creates a separate source file. Do you want to edit an existing sorce file?
Better than doing asm magic
No not in game in the plugin when someone tries to kill it it says a message and gives you poison effect
@weary geyser if you want to modify existing source files, then this might be of more use: https://www.baeldung.com/java-build-compiler-plugin
Please keep mind that these javac tools are not well supported at all. Using them is not easy, there isn't much documentation about them.
entity.setInvulnerable(true);
OMG thanks!
How do they do it?
How can I make a command that doesnt get send to the console when executed?
with a logging filter
hey how do i get like all rows but get only one data? like i have (name, uuid, etc.) and i only want to get name from every row.
?paste
Currently my code: https://paste.md-5.net/abolawebiz.cpp
Only gives me an error for:
java.sql.SQLException: Column Index out of range, 0 < 1.
[11:27:39 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
[11:27:39 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
[11:27:39 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
[11:27:39 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
[11:27:39 WARN]: at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:812)
[11:27:39 WARN]: at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5657)
[11:27:39 WARN]: at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5576)
[11:27:39 WARN]: at pavlyi.authtools.listeners.ImportHandler.importYAML(ImportHandler.java:53)
[11:27:39 WARN]: at pavlyi.authtools.commands.AuthToolsCommand.onCommand(AuthToolsCommand.java:259)
[11:27:39 WARN]: at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[11:27:39 WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
[11:27:39 WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641)
[11:27:39 WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627)
[11:27:39 WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412)
[11:27:39 WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375)
[11:27:39 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[11:27:39 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[11:27:39 WARN]: at java.lang.Thread.run(Unknown Source)
one is a reference comparison the other is a content comparison. Which you use is dependent on what you are actually trying to check
I think even geolyct understands that now, no need to bring it back up
Hey guys i have a problem ...
Im trying to spawn a rainbow sheep but can't figure it out can you help me please ?
Sheep rainbowsheep = (Sheep)block.getWorld().spawnEntity(block.getLocation(), EntityType.SHEEP);
BukkitTask runnable = new BukkitRunnable() {
int colors = 16;
@Override
public void run() {
colors -= 1;
rainbowsheep = block.getWorld().spawn(block.getLocation(), Sheep.class);
rainbowsheep.setCustomName("ยงaSยงbpยงcaยงdlยงevยงfoยงatยงba ยงfavis!");
rainbowsheep.setCustomNameVisible(true);
rainbowsheep.setColor(DyeColors[colors]);
if (colors == 1) {
colors = 16;
}
}
}.runTaskTimer((Plugin) this, 20L, 20L);
this line in particular :
rainbowsheep.setColor(DyeColors[colors]);
Idk how can i convert a int to a DyeColor ?
by not using int to begin with and just use Color
i dont think so you can use int
Jesus wants to iterate through colors, he can choose to store an int or store a color and make indexof calls
there isn't a method in the API to go from int to a color. Would have to map the numbers yourself and keep track of it.
or you can use byte data
but that is deprecated
if i use Color how do i make a loop ?
DyeColor is an enum, it can be enumerated in order
so the issue isn't with the integer variable
Yes that is correct forgot that, in this case you could just simply iterate over the enum itself
Well the other solution i have is to set the name to jeb_
but i can't hide it eaven with setCustomNameVisble(false)
he wants delays between the different colors, that's why iterating over the enum is not a good option
not sure why the delay means you can't
but anyways, I will show you an example where you don't even need to bother with ints at all
he currently iterates over the enum values through indexes, which is a valid concept
never said it wasn't
.
that isn't me saying it isn't a valid concept
so please sush and stop spreading mis-information in what I have stated
lol
he got the basic concept of how to achieve the task, why do you want to change that?
obviously they are having difficulty in translating from integer to colors. If that is the case, why not show a way that just removes the confusion all together o.O
However, I tend to show more then one way of doing something as well
Anyways its fine I will just go do something else if you have such a problem with people showing examples of different ways of doing something ๐
I don't you are the one commenting on everything I have said thus far, and I have only responded
you are the one who pinged me originally about an old and finished conversation, so I stayed for a bit afterwards
Yes originally and then I moved on
as I said, its completely fine I don't have to help people if others have a problem with it
and I pointed out how this is incorrect
are you butthurt?
doesn't change the facts
whatever, I'll go and help him, best I would do is tell him to learn java
*I'll go and you help him
ain't got no interest in spoonfeeding people who don't know java basics
and this is why you don't teach which is completely fine ๐
@tiny mountain give me a bit to finish eating and I will help you out
Alright ty sir
Yo pro coders
hey does anybody know how can i get a data from every row in MySQL ?
or like a list of row
nevermind got it.
You pretty much had it with the way you did it, just was missing the array and I moved your minus of the numbers to the bottom as well as changed it since it isn't necessary to set the variable specifically since we don't use any different objects for it. Changed the int to get the size of DyeColors array. Just removes so called magic numbers. Also changed which number to check to start over as well as the maximum. Arrays start at 0.
Sheep rainbowsheep = (Sheep)block.getWorld().spawnEntity(block.getLocation(), EntityType.SHEEP);
BukkitTask runnable = new BukkitRunnable() {
int colors = DyeColor.values().size();;
DyeColor[] dyes = DyeColor.values();
@Override
public void run()
rainbowsheep = block.getWorld().spawn(block.getLocation(), Sheep.class);
rainbowsheep.setCustomName("ยงaSยงbpยงcaยงdlยงevยงfoยงatยงba ยงfavis!");
rainbowsheep.setCustomNameVisible(true);
rainbowsheep.setColor(dyes[colors]);
if (colors == 0) {
colors = DyeColor.values().size();
} else {
--colors;
}
}
}.runTaskTimer((Plugin) this, 20L, 20L);
was going to show you another way, but this should be sufficient @tiny mountain
there had to fix it, don't want to minus colors just right after it gets reset ๐
Alright ty, im just having problems with DyeColors.values()
what issue are you having?
Dyecolor can't be resolved
ah should be DyeColor
And it should resolve it
if not, just add import org.bukkit.DyeColor
should be at the top with the rest of the imports
i have the import and copy pasted ur code but still not
I fixed the above to remove the s on DyeColor since it isn't plural lol
Also, I assume the issue is in the if check right @tiny mountain ?
if so, the c in DyeColor needs to capitalized, mistake on my part which I also fixed in the above to reflect that XD Never assume that code given will always 100% work straight away. We all make simple mistakes like I did.
alright wait
Almost everything is good
it just can't Invoke size() on the array type DyeColor[]
try using getSize() instead
don't have my IDE opened so I forget which is appropriate since some collections uses size() and others getSize() lol
o.O
arrays have a simple public field called length
Its public final for obvious reasons.
https://paste.md-5.net/etuhaqasip.java
[15:07:14 WARN]: org.apache.commons.lang.UnhandledException: Plugin Arma v1.0 generated an exception while executing task 80
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:911)
at java.util.ArrayList$Itr.next(ArrayList.java:861)
at vinnydgf.arma.Arma.tick(Arma.java:29)
at vinnydgf.arma.Arma$1.run(Arma.java:55)
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
... 3 more```
Probably modification while iterating.
You are also using the ancient version. Is that intended?
Anyways. Send the Arma class
Sometimes we lose grasp on those things because we just swim in higher level implementations and dont see a single array for weeks...
or when you don't have your IDE, it just makes more sense to call it size()
and not length()
๐ซ
@wet breach ok thanks
Adelemphii i have a dark theme, but the window is white
it hungers
Can I get number of online players from Bungeecord as int? From spigot plugin?
Yes. You need to send a message via the plugin messaging channel and listen for a response from the proxy.
So the code compile
But spam errors in console on event and the sheep is normal
Sheep rainbowsheep = (Sheep)block.getWorld().spawnEntity(block.getLocation(), EntityType.SHEEP);
BukkitTask runnable = new BukkitRunnable() {
int colors = DyeColor.values().length;
DyeColor[] dyes = DyeColor.values();
@Override
public void run() {
rainbowsheep.setCustomName("ยงaSยงbpยงcaยงdlยงevยงfoยงatยงba ยงfavis!");
rainbowsheep.setCustomNameVisible(true);
rainbowsheep.setColor(dyes[colors]);
if (colors == 0) {
colors = DyeColor.values().length;
} else {
--colors;
}
}
}.runTaskTimer((Plugin) this, 20L, 20L);
if (subchannel.equals("SomeSubChannel")) - What i should write in SomeSubChannel?
What is the last index of an array with a length of N ?
Read the whole page before attempting to implement it
N ?
No.
Array with length of 5:
[0, 1, 2, 3, 4]
So its N - 1
So where is my error ?
DyeColor.values().length -1;
You are trying to access the array with an index that is equal to its length. So this will throw a ArrayIndexOutOfBoundsException.
Think about where your index is too big and change it to a fitting value.
Or just get spoon fed by this here.
well i tryed but i still get the same error
int colors = DyeColor.values().length -1;
or rainbowsheep.setColor(dyes[colors - 1]);
Look at the part where you reset the color + where it is initialised.
you do the same mistake here too
I like feeding people with spoon.
Sheep rainbowsheep = (Sheep)block.getWorld().spawnEntity(block.getLocation(), EntityType.SHEEP);
BukkitTask runnable = new BukkitRunnable() {
int colors = DyeColor.values().length-1;
DyeColor[] dyes = DyeColor.values();
@Override
public void run() {
rainbowsheep.setCustomName("ยงaSยงbpยงcaยงdlยงevยงfoยงatยงba ยงfavis!");
rainbowsheep.setCustomNameVisible(true);
rainbowsheep.setColor(dyes[colors-1]);
if (colors == 0) {
colors = DyeColor.values().length-1;
} else {
--colors;
}
}
}.runTaskTimer((Plugin) this, 20L, 20L);
break;
so the out of bounds is fixed here right ?
No. Now you are undershooting.
dyes[colors-1] -> dyes[colors]
probably
sadly no
What exception do you got?
(Plugin) this
Thats not possible. You need to pass an instance of your JavaPlugin class.
You can not randomly cast one class to another.
Well i guess i will take more time to learn java i will get back once i have a better base
I use the same code on PlayerJoinEvent (which works fine) on respawn it does nothing. Any reason on why ? The item in question also gets removed on player death with List.remove.
What exactly doesnt work?
Ah player does not get item on respawn event
Why are you iterating through every player on the server when one player dies?
I'll check the api if I can point player to the exact player. I'm fairly new x)
e.getPlayer()
Because you are setting the item for one player N times the amount of other players on the server.
This would be a cleaner refactoring for your event:
Player player = event.getPlayer();
if(!player.hasPermission(...)) {
return;
}
FileConfiguration config = Gat.plugin.getConfig();
if(!config.getBoolean(...)) {
return;
}
boolean isFloodGatePlayer = CheckJavaOrFloodPlayer...;
if(!isFloodGatePlayer) {
return;
}
ItemStack netherStar = new ItemStack(Material.NETHER_STAR);
ItemMeta ... etc
player.getInventory().setItem(config.getInt("Slot"), netherStar);
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Core: Fa
tal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Makes sense thanks
You probably dont have jdk 11 or higher installed.
I do
Open a terminal and type java -version pls
E:\core>mvn clean installjava -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Program Files\apache-maven-3.6.3\bin..
Java version: 1.8.0_212-release, vendor: JetBrains s.r.o, runtime: C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.3\jre64
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
E:\core>
Open a terminal and type java -version pls
Then send a screen
You got a 1.8 jre thats not even up to date.
@ivory sleet currently trying to use morphia with all modules. Either I can strictly restrict morphia to oxide-common or I can use it across all modules. I'm thinking the first one is the better idea to keep components seperate.
I pinged you because anybody else would have no idea what I'm talking about.
Actually in other news I need Sentry for all modules and I don't wanna do it for every single module, how would I do that?
Open your terminal and type echo %JAVA_HOME%
Try both and see if there is a difference
You dont even have any properly installed java version at all
Oh and there is the jre 1.8 again
Just download the latest jdk and install it.
@lost matrix Java doesn't use JAVA_HOME anymore and if I recall no longer sets that variable
Thats news to me. How is the path resolved then?
It uses symlinking and adds the path to the symlink in path environment variable instead of maintain its own environment variable
this way, when it needs to be updated, all that gets changed is the symlink and nothing needs to be done with the path
installing 16 rn
You can btw also download java versions in intellij and have different versions per project
File > Project Structure
However I added JAVA_HOME because unfortunately, maven still requires it XD