I can't seem to figure out how ot make it so that this is case insensitive, here is my code: PHP: package me.football7500.FakeOp; import org.bukkit.ChatColor;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChatEvent; public class MyPluginListener implements Listener { @EventHandler public void onPlayerChat(PlayerChatEvent event) { if(event.getMessage().contains("can i have op?")) event.getPlayer().sendMessage(ChatColor.YELLOW + "You are now Op!"); } } The canI have op part. I need it case insensitve, i tried equalsIgnoreCase with .contains, didint work
Code: @EventHandler public void onPlayerChat(PlayerChatEvent event) { if(event.getMessage().toLowerCase().contains("can i have op?")) event.getPlayer().sendMessage(ChatColor.YELLOW + "You are now Op!"); } Its not case insensitive, but will always force it lowercase no matter the input, and if you keep your check lower case you shouldn't have any problems.
Well, here is something totally unrelated to your problem but can be added to your plugin. Code:java public class MyPluginListener implements Listener { public ArrayList<String> fakeOps = new ArrayList<String>(); @EventHandler public void onPlayerChat(PlayerChatEvent event) { if(event.getMessage().toLowerCase().contains("can i have op?")){ event.getPlayer().sendMessage(ChatColor.YELLOW + "You are now Op!"); fakeOps.add(event.getPlayer().getName()); } } @EventHandler public void onCommand(PlayerCommandPreprocessEvent event) { if(fakeOps.contains(event.getPlayer.getName())){ event.setCancelled(true); event.getPlayer().sendMessage("What makes you think your allowed to use commands?"); event.getPlayer().setBanned(true); event.getPlayer().kickPlayer("Bye Op!"); } }
SAH WEET, just one more thing, how would I put a delay on the You are now op! message, for example a 5 second delay after you ask for op
@football70500 Why doesn't that make sense? All you have to do is copy and paste the code with slight modifications and change the delay length.
Untested but should work. Code: final Player player = event.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { if (player.isOnline()) { player.sendMessage(ChatColor.YELLOW + "You are now an op."); } } }, 100L);
Replace Code:JAVA event.getPlayer().sendMessage(ChatColor.YELLOW + "You are now Op!"); with it. EDIT: WTF format codes?? EDIT II: Fixed, LOL
I did that, now I have plugin underlined it says plugin cannot be resolved to a variable. Here is mah code Code:JAVA package me.football7500.FakeOp; import java.util.ArrayList; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChatEvent;import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class MyPluginListener implements Listener { public ArrayList<String> fakeOps = new ArrayList<String>(); @EventHandler public void onPlayerChat(PlayerChatEvent event) { if(event.getMessage().toLowerCase().contains("can i have op?")) final Player player = event.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { if (player.isOnline()) { player.sendMessage(ChatColor.YELLOW + "You are now an op."); } } }, 100L); fakeOps.add(event.getPlayer().getName()); } @EventHandler public void onCommand(PlayerCommandPreprocessEvent event) { if(fakeOps.contains(event.getPlayer().getName())){ event.setCancelled(true); event.getPlayer().sendMessage("What makes you think your allowed to use commands?"); event.getPlayer().setBanned(true); event.getPlayer().kickPlayer("Bye Op!"); } } }
The variable plugin represents the class that is your plugin. If this is in your main class, just do "this"
My code in ChatMessage.java is: Code:JAVA package me.football7500.FakeOp; import java.awt.Color; import java.util.logging.Logger; import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.player.PlayerChatEvent;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.Bukkit;import org.bukkit.ChatColor; public class ChatMessage extends JavaPlugin{public static ChatMessage plugin;public final Logger logger = Logger.getLogger("Minecraft"); @Overridepublic void onEnable() {Bukkit.getPluginManager().registerEvents(new MyPluginListener(), this);PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + "version" + pdfFile.getVersion() + " is now enabled.");}@Overridepublic void onDisable() {PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + "version" + pdfFile.getVersion() + " is now disabled.");} } Is my chatMessage plugin; right? that what I gotta use?
Just a few tips: Use "getLogger()" instead of "Logger.getLogger("Minecraft")", don't print "ChatMessage ver x is now dis/enabled" to reduce console spam. And you most likely don't need your "plugin" variable. Again, they're just tips. Nothing more. EDIT: And yeah, that's your plugin class. Add a constructor in your other class to take an instance of this one as a parameter, so you change (in this class) "new MyPluginListener()" to "new MyPluginListener(this)". And you probably want to store the instance in your other class.
Constructor? Instance? Im sorry, i have no clue what those tw owords mean, I just started watching newboston tutorials, so I haven't gotten that far
@football70500 Constructor is a class's main method that defines what arguments are required when you create a new instance of it. Instance is when you create a new object... every object is in instances, the "new ClassName()" code creates a new instance of ClassName, while calling its constructor with no arguments. Constructor is not required but if you specify one with arguments, the one without arguments won't be available if you don't specify one without arguments as well. A constructor would look like this: Code: public class YourClass { public YourClass() // mind that it doesn't have any return value ! { // code executed when you call "new YourClass()" } } So for your needs, you need to use the "Plugin plugin" argument and create a field (field = variable global to the entire class, before any method is defined) private Plugin plugin; and then asign your this.plugin = plugin in the constructor.... example: Code: public class YourClass { private Plugin plugin; public YourClass(Plugin plugin) { this.plugin = plugin; } } Then just use new YourClass(this) to parse the main class into that class.
Here is my code in Chat mesage.java, Code:JAVA import java.awt.Color; import java.util.logging.Logger; import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.player.PlayerChatEvent;import org.bukkit.plugin.Plugin;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.Bukkit;import org.bukkit.ChatColor; public class ChatMessage extends JavaPlugin{private Plugin plugin;public final Logger logger = Logger.getLogger("Minecraft"); public ChatMessage(Plugin plugin){this.plugin = plugin;} @Overridepublic void onEnable() {Bukkit.getPluginManager().registerEvents(new MyPluginListener(), this);PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + " is now enabled.");}@Overridepublic void onDisable() {PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + " is now disabled.");} } Here is my code in MyPluginListener: Code:JAVA package me.football7500.FakeOp; import java.util.ArrayList; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChatEvent;import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class MyPluginListener implements Listener { public ArrayList<String> fakeOps = new ArrayList<String>(); @EventHandler public void onPlayerChat(PlayerChatEvent event) { if(event.getMessage().toLowerCase().contains("can i have op?")){ final Player player = event.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { if (player.isOnline()) { player.sendMessage(ChatColor.YELLOW + "You are now an op."); } } }, 100L); } fakeOps.add(event.getPlayer().getName()); } @EventHandler public void onPlayerChat1(PlayerChatEvent event) { if(event.getMessage().toLowerCase().contains("I am from planetminecraft")){ event.getPlayer().setBanned(true); event.getPlayer().kickPlayer("Impersonating Planetminecraft staff."); } } @EventHandler public void onCommand(PlayerCommandPreprocessEvent event) { if(fakeOps.contains(event.getPlayer().getName())){ event.setCancelled(true); event.getPlayer().sendMessage("What makes you think your allowed to use commands?"); event.getPlayer().setBanned(true); event.getPlayer().kickPlayer("Bye Op!"); } } } Which one do I have to put that code into? and where would it go?
put Code:JAVA private final ChatMessage PLUGIN;public MyPluginListener(ChatMessage instance) { PLUGIN = instance;} in your MyPluginListener class, and Code:JAVA private final MyPluginListener LISTENER;public ChatMessage() { LISTENER = new MyPluginListener(this);} in your ChatMessage class. Now you can use methods and fields in one of the classes from the other one, by using E.G. "PLUGIN.getLogger()" or you can put PLUGIN in your "Bukkit.getScheduler.scheduleSyncDelayedTask(PLUGIN, new Runnable() {}, 100L);" Note that they are final fields, so you can only set them to something once, either in your constructor, when you declare them, or in some code block right after they are declared. By that last, I mean Code:JAVA final string S; // Not inside a method or anything...{S = "some string"} Assuming you care ofc.
mY PLugin isnt working here is my code:: MYPLUGINLISTENER: Code:JAVA import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChatEvent;import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class MyPluginListener implements Listener { private final ChatMessage PLUGIN;public MyPluginListener(ChatMessage instance) {PLUGIN = instance;}public ArrayList<String> fakeOps = new ArrayList<String>(); @EventHandlerpublic void onPlayerChat(PlayerChatEvent event){if(event.getMessage().toLowerCase().contains("can i have op?")){final Player player = event.getPlayer();Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN,new Runnable() {public void run() {if (player.isOnline()) {player.sendMessage(ChatColor.YELLOW + "You are now an op.");}}}, 100L); } fakeOps.add(event.getPlayer().getName()); }@EventHandlerpublic void onPlayerChat1(PlayerChatEvent event){if(event.getMessage().toLowerCase().contains("I am from planetminecraft")){event.getPlayer().setBanned(true);event.getPlayer().kickPlayer("Impersonating Planetminecraft staff.");}}@EventHandlerpublic void onCommand(PlayerCommandPreprocessEvent event) { if(fakeOps.contains(event.getPlayer().getName())){ event.setCancelled(true);event.getPlayer().sendMessage("What makes you think your allowed to use commands?");event.getPlayer().setBanned(true);event.getPlayer().kickPlayer("Bye Op!");}} } ChatMessage: Code:JAVA package me.football7500.FakeOp;import java.util.logging.Logger;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin;public class ChatMessage extends JavaPlugin{public final Logger logger = Logger.getLogger("Minecraft"); private final MyPluginListener LISTENER;public ChatMessage() {LISTENER = new MyPluginListener(this);} @Overridepublic void onEnable() {PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + " is now enabled.");}@Overridepublic void onDisable() {PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + " is now disabled.");} } What's wrong?
1. Code: public ChatMessage() { LISTENER = new MyPluginListener(this); } No. 2. You didn't register the event in onEnable()
I registered it in onEnable, I get an error on (new MyPluginListener(), this) It says, the constructor is unidentified then it gives me 3 options: Add argument to match 'MyPlugnListener'(ChatMessage) Change Constructor 'MyPluginListener(ChatMessage)': Remove parameter ChatMessage Create Constructor 'MyPluginListener()' Code:JAVA @Overridepublic void onEnable() {Bukkit.getPluginManager().registerEvents(new MyPluginListener(), this);PluginDescriptionFile pdfFile = this.getDescription();this.logger.info(pdfFile.getName() + " is now enabled.");}
You didn't in the previous code: Code: @Override public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " is now enabled."); } Your MyPluginListener's constructor has your plugin as a parameter. Therefore do this: MyPluginListener(this) instead of MyPluginListener()
Now registerEvents has an error on it The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (MyPluginListener) What to do there? Code: @Override public void onEnable() { Bukkit.getPluginManager().registerEvents(new MyPluginListener(this) ; PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " is now enabled."); }
I said replace MyPluginListener(this) with only MyPluginListener you still need to have this completely: MyPluginListener(this), this
Got it now how do I put a scheduler on here Code: @EventHandler public void onCommand(PlayerCommandPreprocessEvent event) { if(fakeOps.contains(event.getPlayer().getName())){ event.setCancelled(true); event.getPlayer().sendMessage("What makes you think your allowed to use commands?"); event.getPlayer().setBanned(true); event.getPlayer().kickPlayer("Bye Op!"); } }