forum Forumsplay_arrow Minecraft fiber_manual_record Mods

1

Where is the constructor in this?

1 emerald1 reply199 views
created 10/22/2016 2:11 pm by Brevoort43214
last reply 10/22/2016 2:18 pm
Where in this code is the constructor?
(I'm incredibly new to coding so ;/)

package me.themedieval;

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.PlayerAchievementAwardedEvent;

public class EventListener implements Listener{
private Medfre1 plugin;
public EventListener(Medfre1 plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void aListener(PlayerAchievementAwardedEvent event, Medfre1 plugin) {

Player player = event.getPlayer();
double number = Math.random();
this.plugin = plugin;
if(number <= 0.2) {
player.sendMessage(ChatColor.GREEN + "You won a prize for completing an achievement!");
String commandd = plugin.getConfig().getString("Chance1");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandd);
} else if(number <= 0.4) {
player.sendMessage(ChatColor.RED + "You won a prize for completing an achievement!");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 5");

} else if(number <= 0.6){
player.sendMessage(ChatColor.BLUE + "You won a prize for completing an achievement!");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
} else if(number <= 0.8){
player.sendMessage(ChatColor.YELLOW + "You won a prize for completing an achievement!");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
} else if(number <= 0.97){
player.sendMessage(ChatColor.AQUA + "You won a prize for completing an achievement!");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
} else if(number <= 0.99){
player.sendMessage(ChatColor.BOLD + "You won a prize for completing an achievement!");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
}
}
}
Posted by avatar
Brevoort43214
Level 39 : Artisan Modder
12

comment Login or register to post a reply.

1 reply

10/22/2016 2:18 pm
Level 85 : Elite Modder
Silvania Studios
The constructor is the part that prepares the class, or "constructs" it if you will, often setting some variables from the parent class.

It's usually a method with the same name as the class, and it requires arguments that match the parent class. In your case, public EventListener(Medfre1 plugin) is the constructor.


THAT BEING SAID, if you don't even know basic Java terms you should maybe do a few generic tutorials before making a plugin. Plugins and mods are a brilliant way to learn, but you need to know the basic terminology, operator symbols and other special but basic stuff before you can really do much at all.

Planet Minecraft

Browse

Site

© 2010 - 2019
planetminecraft.com

Welcome