OM NOM NOM NOM NOM
This commit is contained in:
parent
ac580c9c37
commit
a6e5c2ad26
5 changed files with 194 additions and 0 deletions
34
src/alisolarflare/townylearn/MainPlugin.java
Normal file
34
src/alisolarflare/townylearn/MainPlugin.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package alisolarflare.townylearn;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import alisolarflare.townylearn.commands.Cbgm0;
|
||||||
|
import alisolarflare.townylearn.commands.Cbgm1;
|
||||||
|
import alisolarflare.townylearn.commands.SetDickmode;
|
||||||
|
|
||||||
|
|
||||||
|
public class MainPlugin extends JavaPlugin{
|
||||||
|
public boolean dickmode;
|
||||||
|
public void onEnable(){
|
||||||
|
registerCommands();
|
||||||
|
registerEvents();
|
||||||
|
}
|
||||||
|
public void registerCommands(){
|
||||||
|
getCommand("cbgm1").setExecutor(new Cbgm1());
|
||||||
|
getCommand("cbgm0").setExecutor(new Cbgm0());
|
||||||
|
getCommand("setdickmode").setExecutor(new SetDickmode(this));
|
||||||
|
}
|
||||||
|
public void registerEvents(){
|
||||||
|
PlotChangeListener plotChangeListener = new PlotChangeListener(this);
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(plotChangeListener, this);
|
||||||
|
}
|
||||||
|
public void setDickmode(boolean YES){
|
||||||
|
dickmode = YES;
|
||||||
|
this.getConfig().set("dickmode", YES);
|
||||||
|
}
|
||||||
|
public boolean getDickmode(){
|
||||||
|
boolean dickmode = this.getConfig().getBoolean("dickmode");
|
||||||
|
this.dickmode = dickmode;
|
||||||
|
return dickmode;
|
||||||
|
}
|
||||||
|
}
|
47
src/alisolarflare/townylearn/PlotChangeListener.java
Normal file
47
src/alisolarflare/townylearn/PlotChangeListener.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package alisolarflare.townylearn;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||||
|
|
||||||
|
public class PlotChangeListener implements Listener{
|
||||||
|
public boolean isInTown;
|
||||||
|
public MainPlugin plugin;
|
||||||
|
public PlotChangeListener(MainPlugin plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){
|
||||||
|
if (plugin.dickmode == false){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
Resident currentResident = new Resident(plotEvent.getPlayer().getName().toLowerCase());
|
||||||
|
TownBlock plot = plotEvent.getTo().getTownBlock();
|
||||||
|
|
||||||
|
if(plot.hasTown()){
|
||||||
|
Town plotTown = plot.getTown();
|
||||||
|
|
||||||
|
if(!(plotTown.hasResident(currentResident))){
|
||||||
|
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(NotRegisteredException e){
|
||||||
|
//thrown by plotEvent.getTo().getTownBlock()
|
||||||
|
//thrown by plotEvent.getTo().getTownBlock().getTown();
|
||||||
|
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/alisolarflare/townylearn/commands/Cbgm0.java
Normal file
23
src/alisolarflare/townylearn/commands/Cbgm0.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package alisolarflare.townylearn.commands;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Cbgm0 implements CommandExecutor{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
|
||||||
|
if (!(sender instanceof Player)){
|
||||||
|
sender.sendMessage("You must be a player to use this command!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
src/alisolarflare/townylearn/commands/Cbgm1.java
Normal file
53
src/alisolarflare/townylearn/commands/Cbgm1.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package alisolarflare.townylearn.commands;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.*;
|
||||||
|
|
||||||
|
public class Cbgm1 implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
|
||||||
|
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("You must be a player to use this command!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
|
||||||
|
if (tb == null) {
|
||||||
|
player.sendMessage("§cYou aren't standing in a town or some other error occured.");
|
||||||
|
player.sendMessage("§cTownBlock is null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Town town;
|
||||||
|
try {
|
||||||
|
town = tb.getTown();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
player.sendMessage("§cYou aren't standing in a town or some other error occured.");
|
||||||
|
player.sendMessage("§cTownBlock's town is not registered.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (town == null) {
|
||||||
|
player.sendMessage("§cERROR: The town you're standing in is Null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Resident res : town.getResidents()){
|
||||||
|
if (res.getName().toString().equals(player.getName().toString())){
|
||||||
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendMessage("Sorry, you're not part of this town");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/alisolarflare/townylearn/commands/SetDickmode.java
Normal file
37
src/alisolarflare/townylearn/commands/SetDickmode.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package alisolarflare.townylearn.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import alisolarflare.townylearn.MainPlugin;
|
||||||
|
|
||||||
|
public class SetDickmode implements CommandExecutor{
|
||||||
|
private MainPlugin plugin;
|
||||||
|
|
||||||
|
public SetDickmode(MainPlugin plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender.getName().equals("Alisolarflare") || sender.getName().equals("iie")){
|
||||||
|
if(args[0] == null){
|
||||||
|
sender.sendMessage("You must use True, False, 1, or 0 as arguments!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args[0].equalsIgnoreCase("TRUE") || args[0].equalsIgnoreCase("1")){
|
||||||
|
sender.sendMessage("Dickmode has been turned on!");
|
||||||
|
plugin.setDickmode(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args[0].equalsIgnoreCase("FALSE") || args[0].equalsIgnoreCase("0")){
|
||||||
|
sender.sendMessage("Dickmode has been turned off!");
|
||||||
|
plugin.setDickmode(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue