InFocus Posted October 4, 2018 Posted October 4, 2018 Hi all, i have just a question. It is possible to restrict all items (armor,weapons,etc etc) and leave just 1 type or armor to access in zone? I mean for VoiceCommand teleport?
0 melron Posted October 4, 2018 Posted October 4, 2018 17 minutes ago, InFocus said: Hi all, i have just a question. It is possible to restrict all items (armor,weapons,etc etc) and leave just 1 type or armor to access in zone? I mean for VoiceCommand teleport? Can you explain it? you need restrictions for the .command or the zone? or both?
0 InFocus Posted October 4, 2018 Author Posted October 4, 2018 I want restrictions for command all items and for exemple for s grade don't ( S grade means armors and weapons)
0 melron Posted October 4, 2018 Posted October 4, 2018 2 minutes ago, InFocus said: I want restrictions for command all items and for exemple for s grade don't ( S grade means armors and weapons) So , a player with atleast 1 S-Grade item equiped is not be able to use the command right?
0 InFocus Posted October 4, 2018 Author Posted October 4, 2018 package handlers.voicedcommandhandlers; import java.util.HashMap; import java.util.Map; import com.l2jserver.gameserver.handler.IVoicedCommandHandler; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.network.clientpackets.Say2; import com.l2jserver.gameserver.network.serverpackets.CreatureSay; /** * @author L2Amyra */ public class FarmZone implements IVoicedCommandHandler { private static final String[] VOICED_COMMANDS = { "easy", "mid", "hard", "dungeon" }; private static final long delay = 5000; // Millisecounds private static Map<Integer, Long> _reuse = new HashMap<>(); @Override public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target) { if (_reuse.containsKey(activeChar.getObjectId())) { if (_reuse.get(activeChar.getObjectId()) > System.currentTimeMillis()) { activeChar.sendMessage("Sorry, you can not use this command. You can use it within " + ((_reuse.get(activeChar.getObjectId()) - System.currentTimeMillis()) / 1000) + " sec's"); return false; } } { if (activeChar.isDead()) { activeChar.sendMessage("You can't teleport while you are dead!"); return false; } else if (activeChar.isInOlympiadMode()) { activeChar.sendMessage("You can't use this command durring olympiad!"); return false; } else if (activeChar.isInDuel()) { activeChar.sendMessage("You can't use this command when you are in duel!"); return false; } else if (activeChar.isInCombat()) { activeChar.sendMessage("You can't use this command when you are in combat!"); return false; } else if (activeChar.getPvpFlag() > 0) { CreatureSay i = new CreatureSay(activeChar.getObjectId(), Say2.PARTY, "admin", "You can't use this command when you are flagged. Try again...!"); activeChar.sendPacket(i); return false; } else if (activeChar.isJailed()) { activeChar.sendMessage("You can't use this command when you are in jail"); return false; } else if (activeChar.getInventory().getInventoryItemCount(57, 0) < 50000) { activeChar.sendMessage("No enough Adena!"); return false; } else if (activeChar.getKarma() > 0) { activeChar.sendMessage("Go away. You are not welcome here !"); return false; } else if (!activeChar.isNoble()) { activeChar.sendMessage("Only Noblesse players can teleport."); return false; } else if (activeChar.getLevel() < 80) { activeChar.sendMessage("You can only use the command after level 80"); return false; } { if (command.startsWith("easy")) { if (!activeChar.isNoble()) { activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true); } if (!(activeChar.getLevel() < 80)) { activeChar.sendMessage("You have been teleported to easy zone "); activeChar.teleToLocation(89006, 27373, -15691); } _reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay); } else if (command.startsWith("mid")) { if (!activeChar.isNoble()) { activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true); } if (!(activeChar.getLevel() < 80)) { activeChar.sendMessage("You have been teleported to mid zone "); activeChar.teleToLocation(89006, 27373, -15691); } _reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay); } else if (command.startsWith("hard")) { if (!activeChar.isNoble()) { activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true); } if (!(activeChar.getLevel() < 80)) { activeChar.sendMessage("You have been teleported to hard zone "); activeChar.teleToLocation(89006, 27373, -15691); } _reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay); } else if (command.startsWith("dungeon")) { if (!activeChar.isNoble()) { activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true); } if (!(activeChar.getLevel() < 80)) { activeChar.sendMessage("You have been teleported to dungeon zone "); activeChar.teleToLocation(89006, 27373, -15691); } _reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay); } } return true; } } @Override public String[] getVoicedCommandList() { return VOICED_COMMANDS; } }
0 Kara Posted October 4, 2018 Posted October 4, 2018 (edited) public boolean hasGradeEquipped(CrystalType type) { return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent(); } //Usage if (activeChar.hasGradeEquipped(CrystalType.S)) { activeChar.sendMessage("You cannot use this command."); return false; } Go ahead say "Thank you everyone except Kara`". Go ahead i dare you :) Edited October 4, 2018 by Kara`
0 InFocus Posted October 4, 2018 Author Posted October 4, 2018 Hh, what's this? :)) and yea, thank you Kara` for reply http://
0 Kara Posted October 4, 2018 Posted October 4, 2018 (edited) 17 minutes ago, InFocus said: Hh, what's this? :)) and yea, thank you Kara` for reply http:// I gave you the code, is time for you to understand how things work by simple observation. If you can't understand that hasGradeEquiped must be in Player.java then you can ask Mr. Professional Moderator Melroni. I gave you the code. Do what you have to do. And next time u call me trash consider that trash like me provide u help and codes since 2012. Edited October 4, 2018 by Kara`
0 melron Posted October 4, 2018 Posted October 4, 2018 (edited) put that method public boolean hasGradeEquipped(CrystalType type) { return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent(); } in Player.class (or what you have.. L2PcInstance?) then you wont have problems.. regarding to Super Duper Kara. the code is working BUT. If we are talking about java and your object may had 5000 'equiped items' you could have big troubles with your way... findFirst() will do the right way (by checking null) and not findAny since we need to know if there is atleast 1 item that is the type we need and not get all those items.. its like you are using for( bla bla) without returning true when you find it Edited October 4, 2018 by melron
0 Kara Posted October 4, 2018 Posted October 4, 2018 (edited) 25 minutes ago, melron said: put that method public boolean hasGradeEquipped(CrystalType type) { return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent(); } in Player.class (or what you have.. L2PcInstance?) then you wont have problems.. regarding to Super Duper Kara. the code is working BUT. If we are talking about java and your object may had 5000 'equiped items' you could have big troubles with your way... findFirst() will do the right way (by checking null) and not findAny since we need to know if there is atleast 1 item that is the type we need and not get all those items.. its like you are using for( bla bla) without returning true when you find it Im proud that after all you learned basics of java but Mr. PRO Melroni i would like to advice you that the findAny() and findFirst() has 0 difference in terms of performance since it won't go though 5000 object you said. Simply because the filter will return max 10 or i dont remember how many equippable object you can have. So the performance here is so little that even a cpu of 1995 wouldn't consider it difference. in 100 000 objects the difference of Any and First is 6 millisecond in i7 https://imgur.com/a/ioTWGcq So even if we do in 100 object the difference is 0. We need move into nanoseconds which again difference is tiny. Edited October 4, 2018 by Kara`
0 InFocus Posted October 4, 2018 Author Posted October 4, 2018 (edited) Well , melron i always will respect you! You are greate developer in java and everywhere in Lineage 2. and i want to understand this public boolean hasGradeEquipped(CrystalType type) { return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent(); } i give you the code, i put this in l2pcinstance and this part of code //Usage if (activeChar.hasGradeEquipped(CrystalType.S)) { activeChar.sendMessage("You cannot use this command."); return false; } in .command? P.S.-And yes. this package no have player.class, so i must move in L2PcInstance Edited October 4, 2018 by InFocus
0 melron Posted October 4, 2018 Posted October 4, 2018 (edited) 27 minutes ago, Kara` said: Im proud that after all you learned basics of java but Mr. PRO Melroni i would like to advice you that the findAny() and findFirst() has 0 difference in terms of performance since it won't go though 5000 object you said. Simply because the filter will return max 10 or i dont remember how many equippable object you can have. So the performance here is so little that even a cpu of 1995 wouldn't consider it difference. in 100 000 objects the difference of Any and First is 6 millisecond in i7 https://imgur.com/a/ioTWGcq So even if we do in 100 object the difference is 0. We need move into nanoseconds which again difference is tiny. What about a small refactored code? https://imgur.com/a/WlU1ThX @InFocus use this Quote return Arrays.asList(getInventory().getItems()).stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent(); Edited October 4, 2018 by melron
Question
InFocus
Hi all, i have just a question. It is possible to restrict all items (armor,weapons,etc etc) and leave just 1 type or armor to access in zone? I mean for VoiceCommand teleport?
70 answers to this question
Recommended Posts