Why won't this work? It should be getting the block 2 down in the Y direction and if it is one of the listed, then do whatever, but it does the 'whatever' whether the block two down is the listed. Code: Code:java @EventHandler public void onPlayerMove(final PlayerMoveEvent e) { if (on == 1) { Player p = e.getPlayer(); Location loc = p.getLocation(); Location loc2 = p.getLocation(); Location loc3 = p.getLocation(); Location loc4 = p.getLocation(); Location loc5 = p.getLocation(); Location loc6 = p.getLocation(); Location loc7 = p.getLocation(); Location loc8 = p.getLocation(); Location loc9 = p.getLocation(); Location loc10 = p.getLocation(); loc.setY(loc.getY() - 2); loc2.setY(loc2.getY() - 1); loc2.setX(loc2.getX() + 1); loc2.setZ(loc2.getZ() + 1); loc3.setY(loc3.getY() - 1); loc3.setX(loc3.getX() - 1); loc3.setZ(loc3.getZ() - 1); loc4.setY(loc4.getY() - 1); loc4.setX(loc4.getX() - 1); loc4.setZ(loc4.getZ() + 1); loc5.setY(loc5.getY() - 1); loc5.setX(loc5.getX() + 1); loc5.setZ(loc5.getZ()); loc6.setY(loc6.getY() - 1); loc6.setX(loc6.getX()); loc6.setZ(loc6.getZ() - 1); loc7.setY(loc7.getY() - 1); loc7.setX(loc7.getX() - 1); loc7.setZ(loc7.getZ()); loc8.setY(loc8.getY() - 1); loc8.setX(loc8.getX()); loc8.setZ(loc8.getZ() + 1); loc9.setY(loc9.getY() - 1); loc9.setX(loc9.getX() + 1); loc9.setZ(loc9.getZ() - 1); loc10.setY(loc10.getY() - 1); Material b = loc.getBlock().getType(); if (b == Material.WATER && p.hasPermission("waterperk.ice") || b == Material.STATIONARY_WATER || b ==Material.ICE) { loc10.getBlock().setType(Material.ICE); loc2.getBlock().setType(Material.ICE); loc3.getBlock().setType(Material.ICE); loc4.getBlock().setType(Material.ICE); loc5.getBlock().setType(Material.ICE); loc6.getBlock().setType(Material.ICE); loc7.getBlock().setType(Material.ICE); loc8.getBlock().setType(Material.ICE); loc9.getBlock().setType(Material.ICE); Just to elaborate a bit more, loc is to get the block two blocks below the player. i then check if that block is either Water, Stationary water and/or Ice and check if they have the permission. The problem is that the block two down can be grass to obsidian and it doesn't work. It everything still gets set to ice. Tried rearranging code, nothing works. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Aperx that's a totally messy code. use loops. try this Code: @EventHandler public void onPlayerMove(final PlayerMoveEvent e) { if (on == 1){ Player p = e.getPlayer(); Location loc = p.getLocation(); loc.setY(loc.getY() - 1); Material b = loc.getBlock().getType(); if (b == Material.WATER && p.hasPermission("waterperk.ice") || b == Material.STATIONARY_WATER || b == Material.ICE) { for(int ix = -1; ix < 2; ix++){ for(int iy = -1; iy < 2; iy++){ Location loc2 = loc; loc2.setX(loc2.getX() + ix); loc2.setY(loc2.getY() + iy); loc2.getBlock().setType(Material.ICE) } } } } }
That might work except my code looks messy as im making a small square where the player is Techy4198 Unless thats what yours dose and i just don't understand it
Code:java BlockFace[] faces = new BlockFace[]{BlockFace.NORTH_WEST, BlockFace.NORTH, BlockFace.NORTH_EAST,BlockFace.WEST, BlockFace.SELF, BlockFace.EAST,BlockFace.SOUTH_WEST, BlockFace.SOUTH, BlockFace.SOUTH_EAST} @EventHandlerpublic void onPlayerMove(final PlayerMoveEvent e) {if (on == 1){if(!p.hasPermission("waterperk.ice"))return; Player p = e.getPlayer();Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);Block r;for(BlockFace face : faces){r = b.getRelative(face);if (r.getType() == Material.WATER || r.getType() == Material.STATIONARY_WATER){r.setType(Material.ICE);}}}} @Techy4198 Might even be a bit less messy :3
Registering events, and it does implement listener. The turning to ice itself works, but it should only be working if two blocks down is water, or ice. xTrollxDudex DrTURTLE2 Can't get anything to work, really need this done, any help is appreciated, i've tried like everything EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Aperx why 2 blocks down? that would be the block under the one that the player is standing on. where is the player, is the block they are standing on, and is the block it is checking, it would be like this: and i'm not sure that's what you want. don't you mean the block the player is actually on/above ? but ok. this one should work. Code: @EventHandler public void onPlayerMove(final PlayerMoveEvent e) { if (on == 1){ Player p = e.getPlayer(); Location loc = p.getLocation(); loc.setY(loc.getY() - 2); Material b = loc.getBlock().getType(); if (p.hasPermission("waterperk.ice") && (b == Material.WATER || b == Material.STATIONARY_WATER || b == Material.ICE)) { for(int ix = -1; ix < 2; ix++){ for(int iz = -1; iy < 2; iy++){ Location loc2 = loc; loc2.setX(loc2.getX() + ix); loc2.setZ(loc2.getZ() + iz); loc2.getBlock().setType(Material.ICE) } } } } }
Tarestudio fixed also Aperx where do you get the variable 'on'? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Have it in my listener Techy4198 Code:java public class WoWListener implements Listener, CommandExecutor { public static int on = 0; Its toggled between 0 and 1 by another listener That one doesn't work either. Also, i don't want people to be able to destroy bases with it, thus why i want it so there must be two layers of water before it allows the water to be turned to ice Techy4198 And yet again im clueless to as why it won't work EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Aperx oh I misunderstood you but now I see you want it to check BOTH blocks below the player. here is the same code just tweaked a bit (also forgot to change one of the iy's to iz in the last one) Code: @EventHandler public void onPlayerMove(final PlayerMoveEvent e) { if (on == 1){ Player p = e.getPlayer(); Location locP = p.getLocation(); Location loc1 = locP.setY(loc.getY() - 1); Location loc2 = locP.setY(loc.getY() - 2); Material b = loc.getBlock().getType(); if (p.hasPermission("waterperk.ice") && (b1 == Material.WATER || b1 == Material.STATIONARY_WATER || b1 == Material.ICE) && (b2 == Material.WATER || b2 == Material.STATIONARY_WATER)) { for(int ix = -1; ix < 2; ix++){ for(int iz = -1; iz < 2; iz++){ Location loc3 = loc1; loc3.setX(loc3.getX() + ix); loc3.setZ(loc3.getZ() + iz); if(loc3.getBlock().getType() == Material.WATER || loc3.getBlock().getType() == Material.STATIONARY_WATER{ loc3.getBlock().setType(Material.ICE) } } } } } } hopefully this one works (and stop using an integer for on, use a boolean instead) what this does is check if the block below the player is either ice or water and the block below that is water, and if so it will turn all the water under the player's feet (in a 3x3 square) into ice. is this what you want? also if it still does not work, I will load it up in eclipse and see what I can do. what is your intention anyway? do you want people to be able to walk on water? if so, I recommend changing it to a 5x5 square
Hello! My fellow friend Aperx! I dont know how to fix it I have a possible fix to all your problems If the code above didn't work, maybe you're not Registering the listener. ! How to do this? Easy!, Let me guide you! Heres an explanation for if youre doing this in 2 Different Classes (Main and the one for the Function) Code:java // This is the class where the Function onPlayerMove is// Replace with your packages name.package your.packages.name; // You NEED these Importsimport org.bukkit.event.player.PlayerMoveEvent;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.Location;import org.bukkit.World;import org.bukkit.block.Block; // replace <YourPluginsClassName> For your plugins name ._. (plop) lol public class <YourPluginsClassName> implements Listener { @EventHandlerpublic void onPlayerMove(final PlayerMoveEvent e) {if (on == 1){Player p = e.getPlayer();Location loc = p.getLocation();loc.setY(loc.getY() - 2);Material b = loc.getBlock().getType(); if (p.hasPermission("waterperk.ice") && (b == Material.WATER || b == Material.STATIONARY_WATER || b == Material.ICE)) {for(int ix = -1; ix < 2; ix++){for(int iz = -1; iy < 2; iy++){Location loc2 = loc;loc2.setX(loc2.getX() + ix);loc2.setZ(loc2.getZ() + iz);loc2.getBlock().setType(Material.ICE)}}}}}} AND MOST IMPORTANT NOW!!! YOUR MAIN CLASS NEEDS TO REGISTER THE LISTENER FOR IT TO WORK!. Code:java // This is the Main class// Replace with your packages name.package your.packages.name; // You NEED these Importsimport org.bukkit.plugin.java.JavaPlugin;import org.bukkit.entity.Player; // replace <YourMainClassName> For your Main plugins name public class <YourMainClassName> extends JavaPlugin { @Overridepublic void onEnable() {// THIS IS WHAT YOU NEED, Replace "YourPluginsClass()" with Your Plugins class name (The one with your onPlayerMove() function.)getServer().getPluginManager().registerEvents(new YourPluginsClass(), this); for(Player p: getServer().getOnlinePlayers()) {//sending a message to all the players online saying that Plugin has been Enabled. (When /Reloaded)p.sendMessage("All set and done, PLUGIN has been Enabled.");}}//just debugging, not needed@Overridepublic void onDisable() {for(Player player: getServer().getOnlinePlayers()) {player.sendMessage("Plugin \u00A7cDISABLED");}} } 200 lines of code more This is all, I havent Officially tested it myself but I did something alike so it doesnt work I think it works ^^ I hope it helps you go through. If it doesnt works its your fault! Its my fault Im sorry! I must have been wrong . PS: The important thing is "getServer().getPluginManager().registerEvents(new YourPluginsClass(), this);" IF you need the one to have all the code in the MAIN class only Reply and ill help. PS2: Excuse my english, Please, it's 3a.m. Lol. Pardon me. PS3: Tsss...~ -KhriztianCraft
I've never tried using a boolean? Anyways, line 6 & 7 of that i get some errors, as well as 10. I think thats to do with b1 and stuff. But i'm on my phone at the moment so i can fix it. Techy4198 And yes, this is to walk on water, why would you suggest 5x5? i thought 3x3 is good as its not to big but still a decent size
Aperx if someone runs really fast on water, a 3x3 can't keep up, so they fall off. and with the current code, it is cabable of making ice underwater, so give me the whole class and I can get it working perfectly. I know why it was giving errors on b1 and b2, I got the locations but forgot to actually initialize the blocks